0% found this document useful (0 votes)
5 views2 pages

Type Casting in Python

Type Casting in Python is the process of converting a variable's datatype to perform specific operations. There are two types of type casting: implicit and explicit. Implicit type conversion occurs automatically by Python to ensure safe evaluation during operations without user intervention.

Uploaded by

86 EXAMS
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Type Casting in Python

Type Casting in Python is the process of converting a variable's datatype to perform specific operations. There are two types of type casting: implicit and explicit. Implicit type conversion occurs automatically by Python to ensure safe evaluation during operations without user intervention.

Uploaded by

86 EXAMS
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Type Casting in Python



Type Casting is the method to convert the Python


variable datatype into a certain data type in order to
perform the required operation by users. In this article, we
will see the various techniques for typecasting. There can
be two types of Type Casting in Python:
 Python Implicit Type Conversion
 Python Explicit Type Conversion

Implicit Type Conversion


Implicit type conversion occurs
when Python automatically converts one data type to
another during an operation to ensure correct and safe
evaluation, without requiring any action from the user.

# Python automatically converts 'a' to int


a = 7
print(type(a))

# Python automatically converts 'b' to float


b = 3.0
print(type(b))

# Python automatically converts 'c' to float


as it is a float addition
c = a + b
print(c)
print(type(c))
# Python automatically converts 'd' to float
as it is a float multiplication
d = a * b
print(d)
print(type(d))

Output
<class 'int'>
<class 'float'>
10.0
<class 'float'>
21.0
<class 'float'>

You might also like