新的节目和我不确定为什么我收到此错误的Python 3.3类型错误:不支持的操作数类型(S)为+:“NoneType”和“海峡”
count=int(input ("How many donuts do you have?"))
if count <= 10:
print ("number of donuts: ") +str(count)
else:
print ("Number of donuts: many")
新的节目和我不确定为什么我收到此错误的Python 3.3类型错误:不支持的操作数类型(S)为+:“NoneType”和“海峡”
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
。所以,行:
print ("number of donuts: ") +str(count)
你有None + str(count)
。
你可能想要的是使用字符串格式化:
print ("Number of donuts: {}".format(count))
你的括号是在错误的地方:这里
print ("number of donuts: ") +str(count)
^
移动它:
print ("number of donuts: " + str(count))
^
或者只是使用逗号:
print("number of donuts:", count)
非常感谢您的帮助! – user2101517 2013-02-23 03:15:59
这适用于我。谢谢..!! – 2016-09-29 10:51:04
在Python 3中print不再是一个声明。你想要做的,
print("number of donuts: " + str(count))
,而不是添加到打印()的返回值(这是无)
+1格式化 – Ric 2013-02-23 03:13:59
非常感谢您的帮助! – user2101517 2013-02-23 03:15:32