HS

harsh_shukla

Intern at Microsoft Updated March 19, 2020, 9:34 a.m. ⋅ 226 views

Null object in Python


A lot of times, we need to check if a value is null. In Python, there is no Null, instead it has None.

To check if a value is Null, we check if a value is None or not.

We use is operator to do the comparision. You can use ==  also,  however, since the operation "is" is defined as the object identity operation, it is probably more correct to use it, rather than "==". 

Syntax to check Noneness of an object is like this:

>>> foo is None
True
>>> foo = 'bar' 
>>> foo is None
False
>>> foo not None
True

 

None is the sole instance of the class NoneType.

None returns False, when converted to bool.

>>> bool(None)
False
>>> not None
True

 



Go back to feed

HackersFriend Updates





View more


Events


Nov. 28, 2018, 5:30 p.m.

Python from zero to hero

place Delhi

View details


Aug. 13, 2018, 5:30 p.m.

Python from zero to hero

place Bangalore ( HackersFriend office BTM Layout)

View details