标准数据类型
Python3 中有六个标准的数据类型:
Number(数字): int、float、bool、complex(复数)
String(字符串)
List(列表)
Tuple(元组)
Set(集合)
Dictionary(字典)
Python3 的六个标准数据类型中:
不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。
小技巧
内置的 type() 函数可以用来查询变量所指的对象类型。
a, b, c, d = 20, 5.5, True, 4+3j
print(type(a), type(b), type©, type(d))
<class ‘int’> <class ‘float’> <class ‘bool’> <class ‘complex’>
isinstance 和 type 的区别在于:
type()不会认为子类是一种父类类型。
isinstance()会认为子类是一种父类类型。
2 / 4 # 除法,得到一个浮点数
0.52 // 4 # 除法,得到一个整数
017 % 3 # 取余
22 ** 5 # 乘方
32