【发布时间】:2021-02-26 09:50:28
【问题描述】:
每当我打印出一个英镑符号后跟一个数字时,我都会收到此错误代码。
Traceback (most recent call last):
File "main.py", line 65, in <module>
print (u"\xA3" + total_cost)
TypeError: can only concatenate str (not "float") to str
这是代码。
total_cost == 10
print (u"\xA3" + total_cost)
我希望它输出 10 英镑。
有人可以帮忙吗?
【问题讨论】:
-
最简单的方法是在
print中使用,而不是+,或者然后将total_cost转换为带有str(total_cost)的字符串。如果要控制打印的位数,请使用 f-strings。
标签: python