Zahl: Vier Untertypen von
Zahlen Ganzzahl: int
Gleitkommazahl: float (keine einfache oder doppelte Genauigkeit)
bool Boolescher Typ: Repräsentiert einen wahren und einen falschen
komplexen komplexen Titel
>>> 1
1
>>> type(1)
<class 'int'>
>>> type(-1)
<class 'int'>
>>> type(1.1)
<class 'float'>
>>> type(1.11111111111111111111)
<class 'float'>
>>> 1+0.1
1.1
>>> type(1+0.1)
<class 'float'>
>>> type(1+1)
<class 'int'>
>>> type(1+1.0)
<class 'float'>
>>>
Beachten Sie den Unterschied zwischen // (Ergebnis vom Typ float abrufen) und // (Ergebnis vom Typ Integer abrufen)
>>> type(1*1)
<class 'int'>
>>> type(1*1.0)
<class 'float'>
>>> type(2/2)
<class 'float'>
>>> type(2//2)
<class 'int'>
>>> 2/2
1.0
>>> 2//2
1
Es sollte jedoch beachtet werden, dass / Division automatisch in float konvertiert wird
// kann als Division verstanden werden und das Ergebnis behält nur den ganzzahligen Teil bei
>>> 2/2
1.0
>>> 2//2
1
>>> 1//2
0
>>>
bool Boolescher Typ bedeutet, auf das Anfangskapital True, False zu achten
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
>>> int(True)//因此将bool类型归为数字类型
1
>>> int(False)
0
>>> bool(1)
True
>>> bool(0)
False
>>> bool(2)//注意数字中只有0表示False其他都表示True
True
>>> bool(-1)
True
>>> bool(0)
False
>>> bool(0b01)
True
>>> bool(0b0)
False
>>> bool('abc') //其余类型中空值表示False其他表示True
True
>>> bool('')
False
>>> bool([1,2,3])
True
>>> bool([])
False
>>> bool({1,1,1})
True
>>> bool({})
False
>>> bool(None)//一个特殊的也表示False
False
Komplexe Zahl : Verwenden Sie j, um die komplexe Zahl anzugeben
>>> 36j
36j