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,145
  • 10
  • 15

2 Answers2

2
if avariable in {5, 6, 7}:
    print 'hit'
Tom Cornebize
  • 1,283
  • 11
  • 31
1

You can try this one:

if avariable in (5,6,7):
      print 'hit'
Timur Osadchiy
  • 4,911
  • 2
  • 22
  • 26