Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for Python: assert command() == False [closed]

I wonder what is better/best:

>>> def command():
...     return False
...
>>> assert command() == False
>>> assert command() is False
>>> assert not command()

Cheers, Markus

like image 667
mhubig Avatar asked Oct 22 '25 12:10

mhubig


1 Answers

Coding conventions can be studied here: PEP 8 Style Guide for Python Code

There you will find:

Don't compare boolean values to True or False using ==

Yes:   if greeting:
No:    if greeting == True:
Worse: if greeting is True:
like image 106
Schuh Avatar answered Oct 24 '25 02:10

Schuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!