Python None Keyword
The Python None keyword is used to define a null value or no value at all. It is not the same as an empty string, a False or a zero. It comes under the class NoneType object. It is a case-sensitive. The void function returns None when executed.
Example
Following is a basic example of the Python None keyword −
var1 = None
if var1 is None:
print("True")
else:
print("False")
Output
Following is the output of the above code −
True
None Keyword in Void Function
The function which does not perform any operations and the body of the function is empty is known as void function. To avoid IndentationError, we use pass keyword. The void function returns None.
Example
Here, we have defined a void function, Tp() and it returned None when executed −
def Tp():
pass
result1 = Tp()
print("The return type of Void Function :",result1)
Data type of None
The None keyword is data-type of the class NoneType object.
Example
Lets try to find the data-type of the None keyword with the following example −
x = None print(type(x))
Output
Following is the output of the above code −
<class 'NoneType'>
None Keyword in class
The functions which are defined inside the class known as methods. If the method is empty it will return None when it is called.
Example
Here, we have created a class,Python with a method,Tp() inside it. When we called the Tp() as it is empty it returned None −
class Python:
def Tp():
pass
Obj1 = Python
print("The return type of empty method :",Obj1.Tp())
Output
Following is the output of the above code −
The return type of empty method : None