Functions
Functions
The reason for the float value not being converted into an integer instead is due to
type promotion that allows performing operations by converting data into a wider-
sized data type without any loss of information.
Explicit Type Conversion
• In Explicit Type Conversion in Python, the data type is manually
changed by the user as per their requirement.
• With explicit type conversion, there is a risk of data loss since we are
forcing an expression to be changed in some specific data type.
• Syntax :
<required_datatype>(expression)
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
Addition of string and integer using explicit conversion
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
Explicit Type Conversion
• str() function – To convert a data Type to Strings
• There is no restriction in this function.
• It will return the string value to everything which is passed with the function
Key Points to Remember
• Type Conversion is the conversion of object from one data type to another
data type.
• Explicit Type Conversion is also called Type Casting, the data types of
objects are converted using predefined functions by the user.