Casting in python

Shiva Burade
1 min readMay 21, 2021

Casting is a process of converting a datatype into another. For example, converting string data into an integer data or vise versa.

There are two kinds of casting — Implicit and Explicit.

Implicit — values converted automatically by the interpreter/compiler.

result of type1 and typ2 converted to float by the python.

Explicit — values are not automatically converted, we need to manually convert them.
Let’s see what happens we don’t convert our values.

This error occurred because implicit conversion failed.

Error occurred because python did not implicitly converted string to integer or vise versa. In such situations we need to manually convert data from one type to the another.

In python we have three functions to convert values from one type to the another.

str(value) — converts value into string.
float(value) — converts value into float.
int(value) — converts value into int.

Please have a look at this short 1-min video to understand how to use this functions.

Thank you and have a nice day :)

--

--

Shiva Burade

Hello, I am software engineer by profession. I write about technology and programming tutorials.