Name = input ("Hey, what's your name ?")
print ("So, your name is") + Name
结果是:
Hey, what's your name ?Robert
So, your name is
Traceback (most recent call last):
File "C:/Users/Angel'94/Desktop/Sal.py", line 2, in <module>
print ("So, your name is") + Name
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
当我在问号后面输入我的名字时,我也想要一个空格。你知道吗
您需要先构建字符串,然后将结果传递给
print()
:您所做的是首先打印
"So, your name is"
,print()
函数在完成时总是返回None
。然后尝试将Name
添加到None
返回值。你知道吗不使用串联,只需将
Name
作为额外参数传递给print()
函数:函数将在两个参数之间插入一个空格。你知道吗
要在提示符上获得空格,只需将其添加到
input()
参数:相关问题 更多 >
编程相关推荐