Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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)

  • 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.

Related questions

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

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...