Open In App

How to return null in Python ?

Last Updated : 28 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, we don't have a keyword called null. Instead, Python uses None to represent the absence of a value or a null value. We can simply return None when you want to indicate that a function does not return any value or to represent a null-like state.

Python
def my_function():
    return None

  # Call the function and store 
  #the returned value in the variable 'result'
result = my_function()
print(result)

Output
None

In Python, None is used to represent a null value or the absence of a result. Whether we are returning it directly from a function, or in a conditional check, None helps us handle cases where no value is available or valid.

Python
def divide(a, b):
  # Check if the divisor 'b' is 0
    if b == 0:
        return None
    return a / b

  # Call the 'divide' function with 10 
  #as the numerator and 0 as the denominator
result = divide(10, 0)
print(result)

Output
None

Next Article
Article Tags :
Practice Tags :

Similar Reads