Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I want to make multiple comparisons at once, of the same type, in a Python program. For example, to check whether all of a certain group of strings are in a longer test string; or whether a specifi...
#1: Initial revision
Simultaneous comparison in Python
I want to make multiple comparisons at once, of the same type, in a Python program. For example, to check whether all of a certain group of strings are `in` a longer test string; or whether a specific variable is equal to any of some test values; etc. I [discovered that these naive approaches won't work](https://software.codidact.com/posts/292968): ```python if my_name and your_name in email: print("The email is about both of us") if cheese == "cheddar" or "edam" or "havarti": print("Yum!") ``` The other Q&A explains why not. The question now is: *what should I do instead, in Python*? How can I write code that does these sorts of comparisons - and more generally, how can I *figure out how to* write the code? And what if I want multiple possibilities on *both* sides of the comparison, or have the possibilities stored in a list (or other sequence)? Are there any special cases or other tricks?