Checking for True or False
5 min readFeb 2
--
How do you check if something is True
in Python? There are three ways:
- One “bad” way:
if variable == True:
- Another “bad” way:
if variable is True:
- And the good way, recommended even in the Programming Recommendations of PEP8:
if variable:
The “bad” ways are not only frowned upon but also slower. Let’s use a simple test: