0% found this document useful (0 votes)
13 views12 pages

Type Casting

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

Type Casting

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Type Casting

Type casting

What is Type casting?


o Type casting is a method or process that converts a datatype into
another datatype in both ways manually and automatically.
o The automatic conversion is done by the compiler and manual
conversion is done by the programmer.
Types of type casting:
 Implicit Type Casting
 Explicit Type Casting
Type Casting

Implicit Type Casting:


o This method converts the datatype into another datatype
automatically.

o In this process, users don’t have to change the types.


Type Casting

Example: Output:
Type Casting

Explicit Type Casting:


o This method needs user involvement to convert the variable data type
into a certain datatype in order to the operation required.
o Type casting can be done with the following datatype functions.
 Int(): python int() function take float or string as an argument and returns
int type object.
 Float(): Python float() function take int or string as an argument and
return float type object.
 Str(): Python str() function takes float or int as an argument and returns
string type object.
Type Casting

Python int to float:


Example: Output:
Type Casting

Python int to string:


Example: Output:
Type Casting

Python float to int:


Example: Output:
Type Casting

Python float to string:


Example: Output:
Type Casting

Python string to int:


Example: Output:
Type Casting

Python string to float:


Example: Output:
Thank You

You might also like