How to scan through list in if statement
-
20-12-2019 - |
Question
I have a Python 3.3 program and I would like to have something like below work. How can I get it to check the list? It simply gives me an error!
app_list = ["Item1", "Item2", Item3"]
elif menu == "open " + in app_list:
do_stuff()
Solution
It sounds like you want something like:
app_list = ["Item1", "Item2", "Item3"]
elif menu.startswith("open ") and menu[5:] in app_list:
do_stuff()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow