python的数据类型
python中数据类型有如下八种
int(整型)
float(浮点型)
bool(布尔型)
str(字符串)
list(列表)
tuple(元组)
set(集合)
dict(字典)
1、int(整型)
int(整型):指不包含小数点的实数,如:1、32、64、1024等等。
在python中与变量一起使用的格式:
# 给变量赋值整型
num1 = 1
num2 = 32
# 输出变量的数据类型
print(type(num1))
print(type(num2))
# 输出变量的值
print(num1)
print(num2)
运行之后的结果:
<class 'int'>
<class 'int'>
1
2
2、float(浮点型)
float(浮点型):指包含小数点的数字,如:1.1、5.8、1589.687。
在python中与变量一起使用的格式:
# 给变量赋值浮点型
f1 = 1.1
f2 = 5.8
# 输出变量的数据类型
print(type(f1))
print(type(f2))
# 输出变量的值
print(f1)
print(f2)
运行之后的结果:
<class 'float'>
<class 'float'>
1.1