0

As above. For example,

if avariable == 5 or avariable == 6 or avariable == 7:
    print 'hit'

What i want to know if there's anyway i can write the conditions without repeating the variable name over and over again, such as:

if variable == 5 or 6 or 7:
     print ' hit'
houdinisparks
  • 1,180
  • 1
  • 10
  • 16

2 Answers2

2
if avariable in {5, 6, 7}:
    print 'hit'
Tom Cornebize
  • 1,362
  • 15
  • 33
1

You can try this one:

if avariable in (5,6,7):
      print 'hit'
Timur Osadchiy
  • 5,699
  • 2
  • 26
  • 28