You are on page 1of 8

Python Type Conversion

and Type Casting


Objectives

What you are going to learn:

✔ What is Type Conversion?

✔ What is Type Casting?

✔ Benefits of Type Conversion and Type Casting


Python Type Conversion and Type
Casting
One of Python's most useful features is its ability to convert
and cast data types. This process is known as type conversion
and type casting. Type conversion and type casting allow
developers to manipulate data types in order to achieve the
desired results in their programs.
What is Type Conversion?

Type conversion is the process of converting one data type


into another. This is done in order to make the data more
suitable for a specific purpose

Python has two types of type conversion.


1. Implicit Type Conversion
2. Explicit Type Conversion
Implicit Type Conversion

In Implicit type conversion, Python automatically

converts one data type to another data type. This

process doesn't need any user involvement.


Implicit Type Conversion
What is Type Casting?

Type casting is the process of converting one data type into


another, but it is done explicitly by the programmer. This is
done in order to make the data more suitable for a specific
purpose. For example, a type casting could be used to
convert a string into an integer so that it can be used in a
mathematical calculation. Type casting is done using the
built-in functions in Python, such as int(), str(), and float().
Explicit Type Conversion

Explicit type conversion is also called typecasting because


the user casts (changes) the data type of the objects.

You might also like