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
  • 577
  • 4
  • 16

1 Answers1

1

You can use something like

if number in [1, 5, 7]:
Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25