如何定义一组变量,使程序响应列表中的任何一项,称为python3

如何定义一组变量,使程序响应列表中的任何一项,称为python3,python,list,if-statement,input,set,Python,List,If Statement,Input,Set,我创建了一个列表,这样如果有人输入列表中的任何项目,它都会打印相同的内容 lista = ["example", "example2"] listb = ["exampleb", "example2b"] choice = input() if choice == lista[]: print("outputa") elif choice == listb[]: print("outputb") 如果用户键入example或example2,它将打印outputa,但如果用户键

我创建了一个列表,这样如果有人输入列表中的任何项目,它都会打印相同的内容

lista = ["example", "example2"]
listb = ["exampleb", "example2b"]
choice = input()
if choice == lista[]:
    print("outputa")
elif choice == listb[]:
    print("outputb")
如果用户键入example或example2,它将打印outputa,但如果用户键入exampleb或example2b,它将打印outputb。 谢谢

使用:

if choice in lista:
    print("a")
elif choice in listb:
    print("b")
`使用:

if choice in lista:
    print("a")
elif choice in listb:
    print("b")
`您是否尝试过在Python中使用运算符?这样你就可以写:

if choice in list_a:
    print("Output A")
elif choice in list_b:
    print("Output B")
您是否尝试过在Python中使用运算符?这样你就可以写:

if choice in list_a:
    print("Output A")
elif choice in list_b:
    print("Output B")

你说得对,谢谢。我真的没想到。我将把你的问题标记为正确的,因为在Python中,它是一个非常酷的操作符,我最喜欢Python的一点是,它的代码就像普通的英语演讲:你说得对,谢谢,我真的没有想到这一点。我会把你的问题标记为正确的问题在Python中是一个非常酷的操作符,我最喜欢Python的一点是代码就像普通的英语演讲:我没有看到问题问题在标题中,对不起,我没有把它包括在主要部分我没有看到问题问题在标题中,对不起,我没有把它包括在主体部分