Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (19k points)

Out of these not None tests.

if val != None:

if not (val is None):

if val is not None:

Which one is preferable, and why?

1 Answer

0 votes
by (106k points)
edited by

  • if val is not None: is preferable not none test.

  • It is preferred because of  Readability counts which are " Good Python is often close to good pseudocode”.

  • ‘is’ keyword is the Pythonic idiom for testing that a variable is not set to None. This idiom has particular uses in the case of declaring keyword functions with default parameters. is test identity in Python. Because there is one and only one instance of None present in a running Python script/program.

If you are looking for upskilling yourself in python you can join our Python Training and learn from the industry expert.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 23, 2021 in Python by Rekha (2.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories