0

I'd like to perform an if condition if a specific list item contains either one out of several numbers:

if firststring[1] == 100 or 40 or 80 or 67:
    print('hallo')

Does this code make sense?

Guy
  • 46,488
  • 10
  • 44
  • 88
  • `if firststring[1] in [100, 40, 80, 67]: ...` – Nir Alfasi May 10 '21 at 12:14
  • Does this answer your question? [Is there a short contains function for lists?](https://stackoverflow.com/questions/12934190/is-there-a-short-contains-function-for-lists) – Nir Alfasi May 10 '21 at 12:14
  • 1
    What is the value of `firststring[1]`? number as int? number as string? string that contains a number? – Guy May 10 '21 at 12:16
  • Does this answer your question? [How to test multiple variables against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-single-value) – AMC May 10 '21 at 14:30
  • Thanks, that seems to work!, the value can be both int or str.. – progammerattempt May 18 '21 at 11:41

1 Answers1

0

You can use python's in:

if firststring[1] in (100, 40, 80, 67):
    print('hi =)')
Tim Jim
  • 620
  • 5
  • 19