Sitemap

Type Conversion in python.

2 min readJun 18, 2026

--

  • Python is dynamically typed language it holds different data types like integer, float, complex etc. The programmer wants to perform certain operation , we need to covert the data from one data type to another data type based on the condition.
  1. What is type conversion ?

Type conversion is the process of converting the data from one type to another data. In python the type conversions are generally two types.
They are :
i) Implicit type conversion
ii) Explicit type conversion

Get Narrasairam’s stories in your inbox

Join Medium for free to get updates from this writer.

i. Implicit type conversion

  • Python Engine converts the data from one data type to another data type automatically without loss of information or data is called Implicit type conversion.
  • Implicit type conversion follows the order of priority during the process of converting the data type so that data cant loss any information.
    1) complex
    2)float
    3)int
  • example 1:
    x = 1
    y = 2.0
    print(x + y) # 3.0
    why it happened?
  • we already learned that the implicit type conversion follows a order of priority, so that float has highest priority then integer, here no lose of data.
  • example 2:
    x = 1
    y = 2.1
    print(x + y) # 3.1
    here is the clear understanding the priority of conversion. if we convert the float to integer it may loss the 0.1 data so here comes the priority.

ii. Explicit type conversion

Explicit type conversion the process of converting the data from one data type to another data type manually by the programmer using constructor, in this type conversion their will be a loss of data.
Types of constructor:
1) int()
2)float()
3)complex()
1.Int()
int() is a constructor which is used to convert the data type into integer from integer and float.
example 1:
x =1
y= int(x) # 1 (# converting integer to integer)
example 2:
a = 1.0
b = 2.1
c = int(a) # 1, no data loss
d= int(b) # 2, here loss of data 0.1 , programmer forcefully converting integer from float.
Int() constructor can’t coverts the complex data type into int. Throughs an error called type error

2.float()
float() is another type of constructor used to covert the data type into float type from integer and float but not complex data type.
example 1:
x = 1
y = float(x) # 1.0 (converting int to float.)
a = 2.0
b = float(a) # 2.0 (converting float to float.)

3.Complex()
complex() is another type of constructor which is used to convert the data to complex from integer, float and complex data type.
example :
x = 1
y = 2.1
z=3+2j
b = complex(x) # 1+0j (int to complex)
a=complex(y) # 2.1+0j( float to complex)
c=complex(z) # 3+2j (complex to complex)

Conclusion
In conclusion that type conversion play a vital role in performing operation in program, implicit type conversion converts automatically without loss of data/ information by the python engine, Explicit type is a manual conversion using constructor by the programmer but may some loss of data.
constructor like int(), float(),complex(). int and float cant covert from complex and always coverts to complex from int, float.

--

--