You are here: Home / Topics / Type casting in python

Type casting in python

Filed under: Python on 2022-08-26 13:27:54

What is type casting -

Conversion of one data type to another type is called type casting that means in programming at runtime we change the type of the data or variable which store data.

Possible Type casting -
int to float
float to int
int to string
numeric string to int
list to string
list to set
set to list, etc.

program -

a=3.12
print(a) print(int(a))
# int to float
a=3
b=float(a)
print(b)

#string to int a='2'
print(int(a))

#list to set
l=[1,2,1,2]
print(set(l))

output-

3.12
3
3.0
2
{1, 2}

In this program, we done different type of type conversion.

About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.