How to convert integer to string in Python?

Better Stack Team
Updated on February 3, 2023

In Python, you can convert an integer to a string by using the str() function. For example:

x = 5
y = str(x)

The output of this code will be the string "5".

Another way to convert integer to string is using the format() function.

x = 5
y = "{}".format(x)

This method can be useful when you have to place the value of an integer variable in a string.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack