1.浮點數的介紹函數
2.浮點型的運算code
a = 1.25 b = 0.3535 print(a-b) #輸出:0.8965000000000001
a = 1 b = 0.25 print(a + b,type(a+b)) #輸出:1.25 <class 'float'> print(a - b,type(a-b)) #輸出:0.75 <class 'float'> print(a * b,type(a*b)) #輸出:0.25 <class 'float'> print(a / b,type(a/b)) #輸出:4.0 <class 'float'>
#整數轉爲浮點數 a = 1 print('a的類型爲:',type(a)) #輸出:a的類型爲: <class 'int'> print(float(a)) #輸出:1.0 print('轉換後a的類型爲:',type(float(a))) #輸出:轉換後a的類型爲: <class 'float'> #字符串轉爲浮點數 b = '123' print('b的類型爲:',type(b)) #輸出:a的類型爲: b的類型爲: <class 'str'> print(float(b)) #輸出:123.0 print('轉換後b的類型爲:',type(float(b))) #輸出:轉換後b的類型爲: <class 'float'>