Numbers of basic data types of Python3

Number: Four subtypes of
numbers Integer: int
Floating point number: float (no single or double precision)
bool Boolean type: Represents true and false
complex complex title

>>> 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'>
>>> 

Note the difference between // (get a result of float type) and // (get a result of integer type)

>>> 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

However, it should be noted that / division is automatically converted to float
// can be understood as a division, and the result only retains the integer part

>>> 2/2
1.0
>>> 2//2
1
>>> 1//2
0
>>> 

bool Boolean type means pay attention to True, False initial capital

>>> 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

Complex number : use j to indicate complex number

>>> 36j
36j
Published 12 original articles · Like1 · Visits 197

Guess you like

Origin blog.csdn.net/qq_39338091/article/details/104869695