Convert integer to string in Python
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Turning an integer into a string is simple in Python, but the best approach depends on what you want the result to look like. Sometimes you only need the plain digits, and other times you want padding, separators, or a non-decimal representation such as hexadecimal.
The standard solution: str()
For ordinary conversion, use str():
This works for negative numbers, zero, and very large integers:
If your only goal is to convert an int into a textual form, str() is the most direct and readable choice.
Building strings with f-strings
If the integer is part of a larger message, f-strings are usually cleaner than converting first and concatenating later:
F-strings also make formatting easy:
That is especially useful for filenames, identifiers, and logs where the integer needs a specific appearance.
Using format() when formatting rules matter
Python's format() function gives the same formatting power without embedding the value directly into a string literal:
This is useful when the format specifier is dynamic or passed in from elsewhere:
Converting lists of integers
When you need to join multiple integers into one string, convert each item first:
Trying to join integers directly raises an error because join() expects strings, not numbers.
This pattern shows up all the time in CSV generation, logs, and command construction.
Decimal versus other bases
An integer can be turned into more than one kind of string. Python includes helpers for common bases:
If you want the base-specific text without the prefix:
That distinction matters when the string is intended for display, serialization, or another system that expects a specific numeric format.
Common Pitfalls
The most common mistake is concatenating a string and an integer directly:
Fix it with str(count) or an f-string:
Another issue is assuming every number-to-string operation is just plain decimal conversion. If the output needs padding, separators, or hex formatting, str() alone is not enough.
Be careful when converting values that are not actually integers. str(True) returns "True", not "1", because True is displayed as a boolean representation. If you need numeric text, convert intentionally.
Finally, when formatting user-facing output, think about locale and presentation rules. The string form that works for logs may not be the right form for a UI or report.
A useful rule of thumb is simple: use str() for conversion, and use formatting tools only when the string has display requirements. That keeps ordinary code easy to read and makes special formatting explicit when it actually matters.
Summary
- Use
str()for plain integer-to-string conversion. - Use f-strings when the integer is part of a larger string or needs formatting.
- Use
format()when the formatting specifier is important or dynamic. - Convert each integer to text before using
join(). - Choose the right representation: decimal, padded decimal, binary, octal, or hexadecimal.

