Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (106k points)

I've always thought of the if not x is None version to be more clear, but Google's style guide and PEP-8 both use if x is not None. Is there any minor performance difference (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?*

*I'm referring to any singleton, rather than just None.

1 Answer

0 votes
by (47.6k points)

You should use if x is not None for readability sake because the bytecode compiler parses both if x is not None and if not x is None into x is not None.

if x is not None: 

X =5 #x can be anything depending on your need

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 31, 2019 in Data Science by sourav (17.6k points)
0 votes
2 answers
asked Oct 3, 2019 in Python by Tech4ever (20.3k points)

Browse Categories

...