說明:
在今天做int實現的過程中,官方函數的解釋是將numeric轉換為integer,就突然不明白,兩個有啥區別。
numeric-數字類型包括:
int,float,bool,complex
integer--整數,是numeric的一部分
實驗:
>>> a,b,c,d = 10,10.1,True,4+3j >>> int(a) 10 >>> int(b) 10 >>> int(c) 1 >>> int(d) Traceback (most recent call last): File "<pyshell#24>", line 1, in <module> int(d) TypeError: can't convert complex to int #但是對於復數是不行的,不能轉換。 >>>
備注:通過實驗可以知道,int能夠轉換整數,浮點數,布爾值為整數。
文檔創建時間:2018年12月7日17:15:14