Python Tutorials
Basic

Data Structure and Data Types

String

List

Tuple

Set

Dictionary

Functions / Methods

Advance

Exception Handling

Python NoneType


NoneType

Python uses the None to represent the absence of a value or a null value.

The None is often used to indicate that a variable or expression has no meaningful value.

The None is commonly used in Python when we need to represent a missing or undefined value.

It's an important concept for handling default or initialise variables, as well as indicating the absence of a result or a condition.


None is Used in Variable Assignments

You can assign the value None to a variable to indicate that it has no initial value.

Example
x = None

Here, we declare a variable x and assign None to the variable x.


None Use in Function Returns

A function that does not have a specific return value, then it returns a None by default.

Example
def python_function():
    pass


print(python_function())
None

In the above example, a function with no return statement. After calling this function, we got the None value in the output.


Comparing to None

You can use the is operator to check if a variable or expression is equal to None.

Example
x = None
if x is None:
    print("x is none.")
x is none.

In the above example, we checked x variable is None or not, if x is None, then print x is none. Here is the output, you can see the text is printed, and x is none.