Write a simple program to explain (using comments) the working of type() function, Python

Q: 2 Write a simple program to explain(using comments) the working of
# type() function

 Full  Sol:


    
    a = 3           # store integer under "a" variable.
    b = 3.1         # store floating point number under "b" variable.
    c = "Planet"    # store string under "c" variable.
    print(type(a))      # type will tell the class of "a" variable.
    print(type(c))      # this type function will tell the class of "c" variable.
    print(type(b))      # this type function will tell the class of "b" variable.



 

With Something  explain:

Comment start with '#' 

Here add 3 types of value (integer, string, float)

store integer 3 under "a" variable.  (a = 3)

second store floating point  number 3.1 under "b" variable. (b = 3.1)

third store string 'Planet' under "c" variable.  (c ="Planet" )


Now know it's class with print and type function.

   
    print(type(a))      # type will tell the class of "a" variable.
    print(type(c))      # this type function will tell the class of "c" variable.
    print(type(b))      # this type function will tell the class of "b" variable.


 

print(type(a)) 
this will tell the class of "a" variable.

print(type(c))
this type function will tell the class of "c" variable.


print(type(b))
this type function will tell the class of "b" variable.


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Post a Comment (0)
Previous Post Next Post