The Wayback Machine - https://web.archive.org/web/20221013015717/https://www.geeksforgeeks.org/python-none-keyword/
Skip to content
Related Articles

Related Articles

Python None Keyword

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 26 Aug, 2022
View Discussion
Improve Article
Save Article

None is used to define a null value or Null object in Python. It is not the same as an empty string, False, or a zero. It is a data type of the class NoneType object. 

Null Vs None in Python

None – None is an instance of the NoneType object type. And it is a particular variable that has no object value. 

Null – There is no null in Python, we can use None instead of using null values.

Note – Python null is refer to None which is instance of the NoneType object type

Example:

Here we will both Null and None and we get the related output for these two statements. Where one of the outputs is Null is not defined.

Python3




print(type(None))
print(type(Null))

Output:

<class 'NoneType'>
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [9], in <cell line: 2>()
     1 print(type(None))
----> 2 print(type(Null))
NameError: name 'Null' is not defined

Null in Python

None is the function returns when there are no return statements.

Python3




def check_return():
    pass
print(check_return())

Output:

None

Referring to the null object in Python

Assigning a value of None to a variable is one way to reset it to its original, empty state.

Example 1:

Python3




# we will check the type of None
print(type(None))

Output:

<class 'NoneType'>

Example 2:

Python3




# declaring a variable as None
var = None
 
# checking it's value
if var is None:
    print("var has a value of None")
else:
    print("var has a value")

Output:

var has a value of None

Note: If a function does not return anything, it returns None in python.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!