1. 程式人生 > >python | 變量與數據 | 數據類型

python | 變量與數據 | 數據類型

oat 小數 總成績 小數點 不能 utf 成績 put int

 1 # coding: utf-8
 2 
 3 a = 3434
 4 b = 456787654567876545678765456767687878
 5 price = 32.43
 6 name = marry
 7 
 8 # 輸出數據類型
 9 print(type(a))
10 print(type(b))
11 print(type(price))
12 print(type(name))
13 
14 # str轉換為int
15 # str中只能是阿拉伯數字,不能含有小數點
16 math_grade = int(input(請輸入數學成績:))
17 english_grade = int(input(
請輸入英語成績:)) 18 total = math_grade + english_grade 19 print(總成績為:%s % total) 20 print(type(total)) 21 22 # float轉換為int 23 # 只保留小數點前面的 24 f = 43.65 25 i = int(f) 26 print(i) 27 print(type(i)) 28 29 # int和float轉換為str 30 f = 23.54 31 i = 343 32 s = str(f) 33 print(s) 34 print(type(s)) 35 s = str(i) 36
print(s) 37 print(type(s)) 38 39 # int和str轉換為float 40 i = 89 41 s = 789.45 42 f = float(i) 43 print(f) 44 print(type(f)) 45 f = float(s) 46 print(f) 47 print(type(f))

python | 變量與數據 | 數據類型