10. Python 'None' Data Type


None:

None means nothing. No value associated. If sometimes in our program to handle the empty data, or sometimes we don’t have any data, then we are using 'None' in the value place

Example

a= 10 # we create the ‘10’ value.

a=None #now ‘10’ replace with None value.

print(type(a)) #now we are checking the data type.

<class 'NoneType'> #Result

One more example:

def f1():                    # take a function

    return 10             # return the value 10

x=f1()                        # now we are calling the function for value x value returned.

print(x)                    # now print the x value.

10                               #result

Same example for the none data type.

def f1():                    # take a function

    print(‘Hi’)           # print the value is Hi.

x=f1()                        # now we are calling the function for value x but its value is not returned. Because we are not assigning the return function.

print(x)                    # now print the x value.

Hi, None                              #result

The Above examples some clarity about the 'None' datatype.

In Python, everything is object only.

a=None. now ‘a’ associated with None object. Once the object is created, then id also available.

Example:

a = None

print(id(a))

print(type(a))

1453018344            #Result

<class 'NoneType'>

In python PVM is smart. For program optimization, for more speed. PVM always trying.

In the 'None' data scenario in the total program, how many times we assign the None data type, but PVM only assigns the single None value only. If we assign the new value of None, then it’s pointing out the before None address.   And the whole program, it’s only one None data type created by PVM.

 

 

Example:

a = None

b = None

c = None

def f1():

    pass

d = f1()

print(a,b,c,d)

print(id(a),id(b), id(c), id(d))

None None None None                                                              #result

1453018344 1453018344 1453018344 1453018344       #result

 


0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post