python小白入门基础(八:自动转换类型)

 

# 自动类型转换 :Number (int floa bool complex)
'''
精度从低到高 bool < int < float < complex
'''

 

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

 

res = True + 99 #输出100
print(res)
res = False + 99 #输出99
print(res)

 

# 2.bool + float
res = True + 0.88 #输出1.88
print(res)
res = False + 7.63 #输出7.63
print(res)

 

#3. bool + complex
res = True + 5+2i #输出6+2i
print(res)

 

#4. int + float
res = 5 + 2.4 #输出7.4
print(res)

 

#5. int + complex
res = 7 + 8-9i
print(res)

 

#6. float + complex
res = 5.5 + 8+2i
print(res)

 

posted on 2020-09-04 20:44  python小达人  阅读(194)  评论(0编辑  收藏  举报