day08数据类型-回顾

一、整型int
1.作用:记录年龄,月份等
2.定义:
age=18 #底层实际上是执行了age=int(18)
3.类型转换
纯数字的字符串能转换成int,float类型能转换成整型int
例:
x=1.1
print(type(int(x)))

msg='1234'
res=int(msg)
print(type(res))

二:float类型
1.作用:用来记录工资,身高等
2.定义:
salary=2.1 #底层实际上是执行了salary=float(2.1)
3.类型转换:int型和纯数字或者待带小数的数字字符串能转换成float型
例:
x=11
print(type(float(x)))

msg='111'
print(type(float(msg)))
msg='11.1'
print(type(float(msg)))

猜你喜欢

转载自www.cnblogs.com/zhangtieshan/p/12458846.html