简体   繁体   中英

How can I print something if an item is in a list?

I am new to python so don't be *facepalm* if you see something that is so easy to solve...

What if condition I need to use to make the print run in the following bit of code I've tried so far (which doesn't work):

Music=["Play Some Music","Open Music","Music","Play"]

Action=(input("Please Select An Action To Do: "))

if Action==Music:

    print("Here Is Your Music")

Since you don't want to check whether the Action is the same as Music list, but only if it is in the Music list, use the in operator:

if Action in Music:

Also, as mentioned in comments, use lower case for variables in python - action instead of Action and music instead of Music . It doesn't matter for the interpreter, but this is the convention, and it will make it easier to work with other people, and easier for them to understand and help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM