in
PYL-R171412 return x % 2 == 0
13
14 def is_prime(x):
15 if x == 0 or x == 1:16 return False
17
18 for i in range(2, x):
140 elif x == 10 or x == 20 or x == 30 and x == 40:
141 print("Sweet!")
142
143 elif x == 10 or x == 20 or x == 30:144 print("Why even?")
145
146
129
130
131def check(x):
132 if x == 1 or x == 2 or x == 3:133 print("Yes")
134 elif x != 2 or x != 3:
135 print("also true")
To check if a variable is equal to one of many values, combine the values into a tuple and check if the variable is contained in
it instead of checking for equality against each of the values.
This is faster, less verbose, and more readable.
if x == 1 or x == 2 or x == 3:
do_something()
if x in (1, 2, 3):
do_something()