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. phone_number = "+919876543210"
print(type(phone_number))
// Output: <class 'str'> (Even though it looks like numbers!)
| Data Component | Value Stored | Python type() Output | Architect's Systems Reason |
|---|---|---|---|
| Phone Number | "+919876543210" |
<class 'str'> | Must preserve symbols (like +) and leading zeros. No arithmetic calculation will ever be performed on it. |
| Postal / PIN Code | "530003" or "02108" |
<class 'str'> | Standard integers automatically drop leading zeros (e.g., 02108 becomes 2108), which destroys valid zip code formats. |
| Vehicle Registration | "AP31AB1234" |
<class 'str'> | An alphanumeric string mix of structural state characters and tracking sequence numbers. |
| Product Stock / Qty | 50 |
<class 'int'> | Represents discrete whole units. Essential for direct count math (like subtracting stock during checkout flows). |
| Product Price / Tax | 199.50 or 0.18 |
<class 'float'> | Contains fractional components and floating decimal points required for calculating financial ledger totals. |
| Account Status Flag | True or False |
<class 'bool'> | Binary condition states used to control conditional statements, system gates, and application routing permissions. |
| Employee ID / Roll No | "EMP0045" |
<class 'str'> | Functions strictly as a unique text label database index rather than an incrementable quantitative amount. |

Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.