自动类型转换

数字类型(Number => int bool float complex)

精度从低->高 排行
bool -> int -> float -> complex
如果两个不同的类型进行运算,
默认低精度向高精度转化

# True -> int 1 False -> int 0
# bool + int
res = True + 14
print(res)


# bool + float # 把False 转换成浮点型0.0 在加上float
res = False + 4.99
print(res)

# bool + complex # 把True 转换成复数1+0j 在加上complex
res = True + 3+4j
print(res)


# int + float # 把int 转换成浮点型7.0 再加上float
res = 7 + 3.66
print(res)


# int + complex # 把int 转换成复数 3+0j 再加上complex
res = 3 + 9-2j
print(res)

# float + complex 把float 转化成复数6.91+0j 再加上complex
res = 6.91 + 11-6j
print(res)

转载于:https://www.cnblogs.com/weekz/p/11128342.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值