Python入門——基本數據類型之int、float


基本數據類型 -- 數字類型之int、float

int類型

定義:

age = 10 # age=int(10)

名字(參數)

print('hello','world')

x=int(10)
print(x) # 10
res=print('xxx') # xxx
print(res) # None 沒有產品

3.類型轉換

  • 純數字的字符串轉成int
res=int('100111')
print(res,type(res)) # 100111 <type int>
  • (了解)
# 十進制轉成其他進制

10進制 -> 二進制

11 - > 1011

1011-> 8+2+1

print(bin(11)) # 0b1011

# 10進制 -> 八進制

print(oct(11)) # 0o13

# 10進制 -> 十六進制

print(hex(11)) # 0xb
print(hex(123)) # 0xb
  • 其他制轉成其十進制
# 二進制->10進制

print(int('0b1011',2)) # 11

# 二進制->8進制

print(int('0o13',8)) # 11

# 二進制->16進制

print(int('0xb',16)) # 11
二:float類型
  • 2、定義
salary=3.1 # salary=float(3.1)
  • 3、類型轉換
res=float("3.1")
print(res,type(res))

使用

int與float沒有需要掌握的內置方法

他們的使用就是數學運算+比較運算


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM