Fork me on GitHub

python自动类型转换(针对于Number数据类型来的)精度从低到高 bool->int-> float->complex 当两个不同是数据类型运算时候,默认想更高进度转化

# ### 自动类型转换(针对于Number数据类型来的)
'''
精度从低到高
bool->int-> float->complex
当两个不同是数据类型运算时候,默认想更高进度转化
'''
# True 转化成整型是1  False转化成整型是0

# bool + int

res = True + 1
print(res)

#boll + float

res = True +4.14
print(res)


#bool+complex
res = False + 3j
print(res)

#int + float
#3.14 15~18本质上存在精度损耗,因为小数的二进制在内存中是无限循环没有终止,一般进行截取15~18位

res = 5+6.88
print(res)

#int +complex
res = 5+(2+3j)
print(res)

#float + complex
res = 3.55 + (-4-2j)
print(res)

  

posted @ 2019-04-25 21:50  MR_黄Python之路  阅读(189)  评论(0编辑  收藏  举报