Consider merging these comparisons with 'in' by using 'x in (10, 20, 30)'. Use a set instead if elements are hashable.
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
Consider merging these comparisons with 'in' by using 'x in (1, 2, 3)'. Use a set instead if elements are hashable.
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")
Description
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.
Bad practice
if x == 1 or x == 2 or x == 3:
do_something()
Recommended
if x in (1, 2, 3):
do_something()