Tutorials  Articles  Notifications  Login  Signup


HS

Harsh Shukla

Intern at Microsoft Updated March 19, 2020, 9:34 a.m. ⋅ 834 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

 



HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account