Pattern: Malformed comparison to True
Issue: -
When comparing a variable to True
, you should use the form if x is True
or simply if x
. The most common incorrect form is if x == True
.
x = True
if x == True:
print('True!')
x = True
if x is True:
print('True!')
or simply:
x = True
if x:
print('True!')