TypeError: unsupported operand type(s) for /: ‘str‘ and ‘int‘

错误复现

# python代码
print('1除以2等于%f' %1/2)

报错

TypeError: unsupported operand type(s) for /: 'str' and 'int'

解决办法

加上括号即可

>>> print('1除以2等于%f' %(1/2))
1除以2等于0.500000

猜你喜欢

转载自blog.csdn.net/shiyuzuxiaqianli/article/details/118581447