Python None Keyword

The "None" keyword in Python is used when we need to declare a variable with no value at all. The interesting thing about the None keyword is that it is a constant value with no value at all.

"None" is neither a 0 nor an empty string like "". That is, "None" is none, nothing else. For example:

a = None
b = 0
c = ""
print(type(a))
print(type(b))
print(type(c))

The output is:

<class 'NoneType'>
<class 'int'>
<class 'str'>

It means that, like 0 is of the "int" type, "" is of the "str" type. Similarly, "None" is of the "NoneType" value.

Note: Python is a case-sensitive language; therefore, keep the first letter of the None keyword in capital letters, and the remaining 3 letters must be in small letters.

Python None Keyword Example

Here is an example of the None keyword in Python. This program demonstrates that a function with no return value will return None.

def funOne():
    x = 10

def funTwo():
    x = 100
    return x

x = funOne()
print(x)

x = funTwo()
print(x)

The output is:

None
100

Advantages of the None keyword in Python

Following is a list of some of the advantages of the "None" keyword in Python.

Disadvantages of the None keyword in Python

Following is a list of some of the disadvantages of the "None" keyword in Python.

Python Online Test


« Previous Tutorial Next Tutorial »


Liked this article? Share it!





Like/follow us on social media for updates!




Like/follow us on social media for updates!