Convert Integer to String in Python
To convert integer to string in python, you can use the str() class constructor with the integer passed as argument to it. str() constructor takes integer as argument and returns string.
myString = str(integer)
In this tutorial, we shall go through some of the examples using str() constructor to convert an integer to a float, with the help of example programs.
Example 1: Typecast Int to String
In this example, we will take an integer, print it and its datatype, convert it to string, and verify if the resulting datatype is string or not.
a = 5 print(a, 'is of type:', type(a)) a = str(a) print(a, 'is of type:', type(a))
5 is of type: <class 'int'> 5 is of type: <class 'str'>
We have converted a from integer to string.
In this tutorial of Python Examples, we converted variable of int datatype to variable of string datatype, with the help of well detailed Python programs.
You must know these.