Python 我能';t调用包含多个单词的变量(如果在变量中:)

Python 我能';t调用包含多个单词的变量(如果在变量中:),python,Python,我试图调用我在Python中为“if”语句创建的变量。 以下是一个总结版本: yes = ("yes", "y") question1 = input("Am I right?") if question1.lower() in yes: print ("you are correct") 但我有一个错误: --'in <string>' requires string as left operand, not builtin_function_or_method 在Python

我试图调用我在Python中为“if”语句创建的变量。 以下是一个总结版本:

yes = ("yes", "y")
question1 = input("Am I right?")
if question1.lower() in yes:
print ("you are correct")
但我有一个错误:

--'in <string>' requires string as left operand, not builtin_function_or_method
在Python2.x中; 您必须使用
raw_input
而不是
input
as
input()
实际上将输入作为Python代码进行计算。
raw\u input()
返回用户输入的逐字记录字符串

yes = ("yes", "y")
question1 = raw_input("Am I right?")
if question1.lower() in yes:
    print("you are correct")

刚刚尝试了您的代码,它非常好。

显示您的实际代码。您现在发布的是正确的代码,只要您在条件语句中正确缩进最后一条print语句,它在Python 3中就可以正常工作。如果您使用的是Python 2,您应该将该输入更改为原始输入。您确定您编写了
.lower()
,而不是
.lower
?@Barmar好的,谢谢,我会这样做的。现在,你能告诉我当我问这个问题的时候,我做错了什么,以便下次我能把它做对吗?haha@Barmar谢谢,我会让我的下一个问题更简洁,并且仔细研究。我很感激,伙计们!不幸的是,我使用的是Python 3.x!:(我知道这一点,但是,我很感激!这不是标记为Python 2的,而且无论如何都会引发完全不同的错误。除了打印函数缩进之外,我当时没有看到任何错误。请重新检查您的输入,因为您可能输入了换行符;或者可能没有被视为字符串的内容。
yes = ("yes", "y")
question1 = raw_input("Am I right?")
if question1.lower() in yes:
    print("you are correct")