Welcome To
Type Casting


Type conversion In Python

The type conversion is a process of converting a data from one data type to another datatype is called type conversion and it is also called casting. The python provides the some built in type casting functions to conversion a one type to another type

The python supports a two types of type casting

  1. Implicit Type conversion
  2. explicit type conversion

Example

Concerting Int to Float

Converting int to str

Implicit Type Conversion

It is a type of data type conversion Implicit type conversion is a process of converting one datatype to another data type automatically the programmer does not convert this data type but the python interpreter convert the data type automatically. this is support only number datatype. Examples in below

Examples

x=10
y=10.20
print(x+y) # converting int to float

x=10
y=10+20j
Print(x+y) # converting int to complex



Explicit Type Conversion

It is a process of converting a one datatype to another datatype when it is require . the programmer by using the functions to convert the one datatype to other explicitly. Examples in the below.

Examples

x=10
print(str(x))# converting int to str

x=[10,20,"darshan"]
print(tuple(x)) # converting list to tuple