0

I would like to have an if statement where the match is one of several numbers without using a large number of | bars because I have many matching cases

if number == 1 | number == 5 | number == 7
  do stuff

In R, there is the operand %in% that works sort of like the following:

if number %in% [1,5,7]
  do stuff

Is there a similar operand/ability in python?

Thanks

C. Denney
  • 537
  • 3
  • 15

1 Answers1

1

You can use something like

if number in [1, 5, 7]:
Michael Bianconi
  • 4,942
  • 1
  • 8
  • 23