Home » Python programs

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.
Submitted by Pankaj Singh, on September 29, 2018

Declare different types of variables; print their types, ids and variables in Python.

There are two 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.

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'}   





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.