0 votes
1 view
in Python by (47.8k points)

I have a method that sometimes returns a NoneType value. So how can I question a variable that is a NoneType? I need to use if method, for example

if not new:

new = '#'

I know that is the wrong way and I hope you understand what I meant.

1 Answer

0 votes
by (107k points)

As you want to “test” NoneType in python you can use is an operator, like as follows:-

if variable is None:

if variable is not None:

Comparisons to singletons like None should always be done with is or is not, never the equality operators.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 15, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...