Python | Declare different types of variables, print their values, types and Ids

Here, we are going to learn all about the different types of the variables in python. We will declare the variables; print their data types, ids (unique identification number) and value. By Pankaj Singh Last updated : April 08, 2023

Declare different types of variables, print their values, types, and Ids

There are the following inbuilt functions are using in the program:

  1. type() - its returns the data type of the variable/object.
  2. id() - it returns the unique identification number (id) of created object/variable.
  3. print() - to print the values.

Program

print("Numbers")
print("---------------------------------")
a=10
print(type(a),id(a),a)
a=23.7
print(type(a),id(a),a)
a=2+6j
print(type(a),id(a),a)


print("\nText")
print("---------------------------------")
a='h'
print(type(a),id(a),a)
a="h"
print(type(a),id(a),a)
a='hello'
print(type(a),id(a),a)
a="hello"
print(type(a),id(a),a)

print("\nBoolean")
print("---------------------------------")
a=True
print(type(a),id(a),a)

print("\nFunction")
print("---------------------------------")
def fun1():
    return "I am Function"
a=fun1
print(type(a),id(a),a())

print("\nObjects")
print("---------------------------------")
class Demo:
    def hi(self):
        return "Hi"
a=Demo()
print(type(a),id(a),a.hi())

print("\nCollections")
print("---------------------------------")
a=[1,2,3]
print(type(a),id(a),a)
a=[]
print(type(a),id(a),a)
a=(1,2,3)
print(type(a),id(a),a)
a=()
print(type(a),id(a),a)
a=1,2,3
print(type(a),id(a),a)
a={1,2,3}
print(type(a),id(a),a)
a={}
print(type(a),id(a),a)
a={"id":1,"name":"pooja"}
print(type(a),id(a),a)

Output

Numbers
---------------------------------
<class 'int'> 10455328 10
<class 'float'> 139852163465696 23.7
<class 'complex'> 139852162869456 (2+6j)

Text
---------------------------------
<class 'str'> 139852162670976 h   
<class 'str'> 139852162670976 h   
<class 'str'> 139852162911512 hello    
<class 'str'> 139852162911512 hello    
  
Boolean
--------------------------------- 
<class 'bool'> 10348608 True 
  
Function 
--------------------------------- 
<class 'function'> 139852163226616 I am Function 
  
Objects
--------------------------------- 
<class '__main__.Demo'> 139852162234016 Hi  
  
Collections   
--------------------------------- 
<class 'list'> 139852162259208 [1, 2, 3]    
<class 'list'> 139852162261256 [] 
<class 'tuple'> 139852162244752 (1, 2, 3)   
<class 'tuple'> 139852182028360 ()
<class 'tuple'> 139852162244968 (1, 2, 3)   
<class 'set'> 139852163034472 {1, 2, 3}
<class 'dict'> 139852163024776 {} 
<class 'dict'> 139852163024584 {'id': 1, 'name': 'pooja'}   

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.