The None object in Python

The None object is used to represent the absence of a value. It is similar to null in other programming languages.

Like other “empty” values, it is False when converted to a Boolean variable.

Example:

>>> None == None
True
>>> None
>>> print(None)
None
>>>

The None object is returned by any function that doesn’t explicitly return anything else.

Example:

def my_func():
	print("Hi there!")

var = my_func()
print(var)

The output in the terminal will be:

ddn_ro@linux:~/Desktop$ python file.py
Hi there!
None
ddn_ro@linux:~/Desktop$

Leave a Reply