There are several data types in Python, e.g. string, float, integer, boolean, etc. One can use the type() function to print the data type of a variable. For example,
n = 10 print(type(n))
Here, n is an integer. So, the above program will print the following output:
<class 'int'>
But, let’s say a variable named “number” contains a float value. But, later, we want to convert the float to an integer and use that integer for a different purpose. We can use typecasting for that purpose.
number = 10.5 index = int(number) print(index)
The output will be:
10 <class 'int'>
Using typecasting in Python, we can convert one data type to another data type. There are two types of typecasting in Python:
- Implicit Typecasting
- Explicit Typecasting
What is implicit typecasting in Python?
Let’s say there is one integer number_int and one float number_float. Now, we want to multiply both the numbers and put the resultant value in another …






0 Comments