None In Python


To represent the absence of a value "None" is used in Python. "None" is the equivalent of "null" in other programming languages. Often "None" is used to initialize any identifier before they are initialized with appropriate values. In Python, the value "None" is of type NoneType. NoneType has only one value that is "None".

Example for None in Python:

class Part:

    # Before the object is initialised by the constructor it is defined to have a value of None

    myId = None


    def __init__(self, aId_in):

        self.myId = aId_in


Part1 = Part(12)

print("Id of Part1 : {}".format(Part1.myId))

Output of the python example program using None:

Id of Part1 : 12


Copyright 2024 ©