print(type(5)) #<class 'int'>
print(type(3.4)) #<class 'float'>
print(type(5+9j)) #<class 'complex'>
Using List , set , dictionary and tuple.
print(type(['One','Tow','Three'])) # <class 'list'>
print(type(('One','Tow','Three'))) # <class 'tuple'>
print(type({'One','Tow','Three'})) # <class 'set'>
print(type({1:'Alex',2:'Ronald',3:'John'})) # <class 'dict'>
a=None
print(type(a)) # <class 'NoneType'>
x=range(5) # 5 is stop value
print(type(x)) # <class 'range'>
a=True
print(type(a)) # <class 'bool'>
print(type("Welcome")) #<class 'str'>
Apart from these built in data types, user can create its own data types by using class.
class Animal():
#instance attributes
def __init__(self1,name1,age):
self1.name= name1
self1.age=age
#instantiate the Animal class
tiger=Animal("Ronald",5) # tiger is an object of Animal class
print(type(tiger)) # <class '__main__.Animal'>
my_int=5 # integer data type
print(type(my_int)) # <class 'int'>
my_int=str(5) # converted to string
print(type(my_int)) # <class 'str'>
Integer to float()
my_int=5
my_int=float(5)
print(type(my_int)) # <class 'float'>
my_data=5.0
print(type(my_data)) # <class 'float'>
my_data=int(my_data)
print(my_data) # 5
print(type(my_data)) # <class 'int'>
Update the above variable like this and check the result.
my_data=5.86
Integer to complex, by using complex()
my_int1=5
my_int2=3
my_int=complex(my_int1,my_int2)
print(type(my_int)) # <class 'complex'>
Float to Integer by using int()
my_float=5.4
my_int=int(my_float)
print(type(my_int)) # <class 'int'>
All types of conversion are not possible. This will generate error.
my_str='plus2net'
my_int=int(my_str)
print(type(my_int))
Output
ValueError: invalid literal for int() with base 10: 'plus2net'
i=5
In above code , i is one object of integer class or data type. Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.