Python字符串不工作(=)
以下是我的语法:Python字符串不工作(=),python,Python,以下是我的语法: input("Has the phone got wet?") if input is "yes".strip('\n'): print("that's the problem") else: print("okay") 尝试使用==而不是is: answer = input("Has the phone got wet?") if answer == "yes": print("that's the problem") else: prin
input("Has the phone got wet?")
if input is "yes".strip('\n'):
print("that's the problem")
else:
print("okay")
尝试使用==而不是is:
answer = input("Has the phone got wet?")
if answer == "yes":
print("that's the problem")
else:
print("okay")
使用
input
时,将端子上的值以引号形式传递。喜欢
电话湿了吗?“是的”
不是这样的:
电话湿了吗?是的
如果您不想键入引号,可以使用
raw\u input
但是您的示例不包含==。此外,请正确标记您的问题;许多回答者只听某些标签。is
与=
不同。strip('\n')
只是“yes”
您需要分配给变量user\u input=input(“手机湿了吗?”)
<代码>如果用户输入==“是”:什么是“不工作”?打个招呼。如果没有其他内容,则将str.strip
应用到比较的错误一侧,与函数(而不是其返回值)进行比较,并通过标识进行比较。对于python2,使用原始输入而不是仅输入。您正在测试input
是否等于“yes”
No实际上-如果存在prompt参数,则将其写入标准输出,而不带尾随换行符。然后,该函数从输入中读取一行,将其转换为字符串(去掉尾随的换行符),并返回该字符串。“-恐怕您完全错了,您需要将返回的值存储为变量,然后将其与“yes”
(请参阅我对该问题的评论)哦,是的,我肯定在想smth(其他)你当然是对的