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.
ExampleFollowing 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 −
TrueNone 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.
ExampleHere, 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.
ExampleLets 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.
ExampleHere, 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
python_keywords.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4