Python Notes
Python Notes
Type Conversion
The process of converting the value of one data type (integer, string, float,
etc.) to another is called type conversion. Python has two types of type
conversion.
print("Value of num_new:",num_new)
print("datatype of num_new:",type(num_new))
Here, num_new has float data type because Python always converts smaller
data type to larger data type to avoid the loss of data.
Here is an example where Python interpreter cannot implicitly type convert.
print(num_int+num_str)
Explicit Conversion
In case of explicit conversion, you convert the datatype of an object to the
required data type. We use predefined functions like int(), float(), str() etc.
to perform explicit type conversion. For example:
print(num_int+num_str)