Python 自动类型转换

时光毁灭记忆、已成空白 提交于 2019-11-27 03:07:12

当2个不同类型的数据进行运算的时候,默认向更高精度转换
数据类型精度从低到高:  bool int float complex

自动类型转换 Number ( int float bool complex )

"""
精度从低到高 顺序 bool < int < float < complex
自动类型转换,默认向高精度,依次转化
"""

# 1.bool + int
"""
bool = True ==>1
bool = False ==>0 
"""

res = True + 88
print(res)

# 2.bool + float
res = True + 8.8
print(res)

# 3.bool + complex
res = True + 3j
print(res)

# 4. int + float
res = 30 + 8.8
print(res)

# 5.int + complex
res = 88 + 6j
print(res)

# 6.float + complex
res = 8.88 + 3j
print(res)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!