PythonStudy——数字类型 Number type

时间:2023-11-16 10:09:08
# 了了解:py2中小整数用int存放,大整数用long
# 1.整型
num = -1000000000000000000000000000000000000000000000000
print(num, type(num))
# 2.小数
num = 3.14
print(num, type(num))
# 3.布尔
res = True
print(res, type(res), isinstance(res, int))
print(3.14 + True)
# 4.复数
num = complex(5, 4)  # 5 + 4j
print(num + (4 + 5j))
# 重点:数字类型直接的相互转化 *****
a = 10
b = 3.74
c = True
print(int(a), int(b), int(c))
print(float(a), float(b), float(c))
print(bool(a), bool(b), bool(c))