codescracker
python

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, 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 int type, "" is of str type. Similarly, None is of NoneType value.

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

Python None Keyword Example

Here is an example of 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

Python Online Test


« Previous Tutorial Next Tutorial »



© Copyright 2021. All Rights Reserved.

CodesCracker