0 votes
1 view
in Python by (17.4k 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 (107k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...