如何修复“TypeError:不支持的操作数类型+:'NoneType'和'str'"? [英] How to fix "TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'"?
本文介绍了如何修复“TypeError:不支持的操作数类型+:'NoneType'和'str'"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定为什么会收到此错误
I am unsure why I am getting this error
count=int(input ("How many donuts do you have?"))
if count <= 10:
print ("number of donuts: " ) +str(count)
else:
print ("Number of donuts: many")
推荐答案
在python3中,print
是一个返回None
的函数.因此,该行:
In python3, print
is a function that returns None
. So, the line:
print ("number of donuts: " ) +str(count)
你有None + str(count)
.
您可能想要的是使用字符串格式:
What you probably want is to use string formatting:
print ("Number of donuts: {}".format(count))
这篇关于如何修复“TypeError:不支持的操作数类型+:'NoneType'和'str'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文