Python3 基础数据类型 - Number 类型
Number(数字)
Python3 支持 int、float、bool、complex(复数)。
在 Python 3 里,只有一种整数类型 int,表示为长整型,没有 Python 2 中的 Long。
内置的 type() 函数可以用来查询变量所指的对象类型。
a, b, c, d = 10, 4.5, True, 1+2j
print(type(a))
print(type(b))
print(type(c))
print(type(d))<class 'int'>
<class 'float'>
<class 'bool'>
<class 'complex'>注意:
- Python 可以同时为多个变量赋值,如
a, b = 1, 2。 - 一个变量可以通过赋值指向不同类型的对象。
- 数值的除法包含两个运算符:/ 返回一个浮点数,// 返回一个整数(向下取整)。
- 在混合计算时,Python 会把整型自动转换为浮点数。