Python Convert Int to String

Convert Int to String

To convert given integer value to string in Python, call str() builtin function and pass the integer as argument to the str() function. str() returns the string formed using the given value.

The syntax to convert an integer a into string is as shown in the following.

myString = str(a)

In this tutorial, we shall go through some of the examples using str() builtin function to convert an integer into a string.

Examples

1. Convert given integer value to a string value

In the following program, we will take an integer in variable a, convert it to string using str().

Python Program

# Take an int
a = 5
print('Input', a, type(a), sep='\n')

# Convert int to string
output = str(a)
print('\nOutput', output, type(output), sep='\n')
Run Code Copy

Output

Input
5
<class 'int'>

Output
5
<class 'str'>

Summary

In this tutorial of Python Examples, we learned to convert a value of int datatype to a value of string datatype using str() function.

Related Tutorials

Code copied to clipboard successfully 👍