Python None is a special object of the NoneType class. It is used to define a null variable or an object. Syntax of
None as follows:
Using Python None as an initial value for a variable
state = None
Note: None is not the same as False or empty string or 0. If the function doesn’t return anything that means its None in Python.
None in Python
Simple example code.
x = None print(x) print(type(x)) print(None) print(type(None))
Checking if a variable is None using is operator:
x = None if x is None: print("Variable value is None") else: print(x)
Output: Variable value is None
if you use equality (
is operator to compare
None, you’ll get the result of
print(None == None) print(None is None)
Python Null and None Keyword
There’s no null in Python; instead, there’s None.
Do comment if you have any doubts or suggestions on this Python basic topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.