Converting an Int to string
Converting an int datatype to string can be done with the use of str() function.
Syntax: str(object, encoding=’utf-8′, errors=’strict’)
Parameters:
object: The object whose string representation is to be returned.
encoding: Encoding of the given object.
errors: Response when decoding fails.
Example:
Python3
hdv = 0x1eff print ( 'Type of hdv :' , type (hdv)) # Converting to string hdv = str (hdv) print ( 'Type of hdv now :' , type (hdv)) |
Output:
Type of hdv : <class 'int'> Type of hdv now : <class 'str'>
String to Int and Int to String in Python
Python defines type conversion functions to directly convert one data type to another. This article is aimed at providing the information about converting a string to int and int to string.