What’s New ?

The Top 10 favtutor Features You Might Have Overlooked

Read More
Computer Science

Convert Int to String in Python (6 Ways with Examples)

Jul 18, 2026 5 Minutes Read Why Trust Us Why you can trust this guide. Written by working engineers and reviewed by our editorial team under a strict editorial policy for accuracy, clarity and zero bias. Shivali Bhadaniya By Shivali Bhadaniya Shivali Bhadaniya Shivali Bhadaniya
I'm Shivali Bhadaniya, a computer engineer student and technical content writer, very enthusiastic to learn and explore new technologies and looking towards great opportunities. It is amazing for me to share my knowledge through my content to help curious minds.
Connect on LinkedIn →
Convert Int to String in Python (6 Ways with Examples)

In Python, the standard way to convert an integer to a string is the built-in str() function. Python also offers f-strings, the format() method, the % operator, repr(), and map() with join() for whole lists.

The conversion matters because integers and strings do not mix. Joining an int to a string with +, writing numbers into a text file, or building an ID like "INV-042" all need the number as text first.

How Do You Convert an Int to a String in Python?

Call str() with the integer as its argument, and it returns the same digits as a string. An integer is a whole number you can do maths with, while a string is a sequence of characters. The digits look identical after conversion, but the type changes:

age = 25
text = str(age)

print(text)        # Outputs: 25
print(type(age))   # Outputs: <class 'int'>
print(type(text))  # Outputs: <class 'str'>
The integer 25 as a number you can do maths with next to the string 25 as text characters

6 Ways to Convert Int to String in Python

Python gives you six ways to get from a number to text. The first two cover nearly every situation, and the rest appear in specific contexts:

The six conversion methods str, f-string, format, percent operator, repr, and map with join shown side by side

1) The str() Function

str() converts its argument to a string. It accepts any Python data type, including integers, floats, and booleans:

views = 1048
print(str(views))          # Outputs: 1048
print(str(views) + " views")  # Outputs: 1048 views

2) F-strings

An f-string embeds a value directly inside text. Any integer placed between the braces is converted to a string automatically, which makes f-strings the standard choice when the number is part of a sentence:

name = "riya"
score = 87
message = f"{name} scored {score} points"
print(message)  # Outputs: riya scored 87 points
Anatomy of an f-string showing the f prefix, the fixed text, and the braces where the variable is converted

F-strings also accept format specifications inside the braces, covered in the string formatting lesson.

3) The format() Method

The format() method fills the {} placeholders in a string with its arguments, converting each one to text. It does the same job as an f-string and appears often in code written before Python 3.6, where f-strings were not available:

order = 42
label = "Order number {}".format(order)
print(label)  # Outputs: Order number 42

4) The % Operator

The % operator is Python's oldest formatting style. The %s marker inside the string is replaced by the value on the right, converted to a string:

day = 18
note = "Backup ran on day %s" % day
print(note)  # Outputs: Backup ran on day 18

5) The repr() Function

repr() returns the developer representation of a value. For integers the result matches str(), but for values like strings the two differ, because repr() includes the quotes:

n = 250
print(repr(n))    # Outputs: 250
print(str("5"))   # Outputs: 5
print(repr("5"))  # Outputs: '5'

6) map() with join() for a List of Numbers

join() only accepts strings, so a list of integers must be converted first. map(str, numbers) applies str() to every element in one pass:

scores = [98, 87, 92]
line = ", ".join(map(str, scores))
print(line)  # Outputs: 98, 87, 92
A list of integers passing through map with str and then join to become one comma separated string

When to Use Each Method

All six produce a string, so the choice depends on the situation:

MethodUse it for
str()A plain conversion with no surrounding text
f-stringEmbedding the number inside a sentence or template
format()The same job in code that must run on Python older than 3.6
% operatorReading and maintaining older codebases
repr()Debug output that shows exactly what a value is
map() + join()Converting every number in a list at once

Examples of Converting Int to String

1) Fixing the TypeError When Concatenating

Adding an integer to a string with + raises an error, because Python does not convert between the two types automatically:

count = 3
print("You have " + count + " new messages")
# TypeError: can only concatenate str (not "int") to str

Converting the number first fixes it, and an f-string avoids the problem entirely:

count = 3
print("You have " + str(count) + " new messages")
# Outputs: You have 3 new messages

print(f"You have {count} new messages")
# Outputs: You have 3 new messages

2) Padding Numbers With Leading Zeros

IDs and filenames often need a fixed width, such as 007 instead of 7. The zfill() string method pads with zeros, and a format specification does the same inside an f-string:

order = 7
print(str(order).zfill(3))  # Outputs: 007
print(f"INV-{order:03d}")   # Outputs: INV-007

3) Adding Commas to Large Numbers

A comma in the format specification groups thousands, which makes large numbers readable in reports:

population = 1406000000
print(f"{population:,}")  # Outputs: 1,406,000,000

Learn More About Int to String Conversion

Converting an Int to Binary or Hex Text

bin() and hex() return prefixed strings, while format() with a base code returns the bare digits:

n = 255
print(bin(n))          # Outputs: 0b11111111
print(hex(n))          # Outputs: 0xff
print(format(n, "b"))  # Outputs: 11111111
print(format(n, "x"))  # Outputs: ff

Converting a String Back to an Int

The int() function reverses the conversion. It accepts digits with optional whitespace around them, and raises a ValueError for anything else:

print(int("42") + 8)  # Outputs: 50

print(int("42abc"))
# ValueError: invalid literal for int() with base 10: '42abc'

Key Takeaways for Int to String Conversion

  • Default to str() - It converts any integer to a string in one call with nothing else around it.
  • F-strings for text - When the number sits inside a sentence, f"{value}" converts and formats in one step.
  • Older styles still appear - format() and the % operator do the same job in pre-3.6 codebases.
  • Lists need map() - join() rejects integers, so convert with ", ".join(map(str, numbers)).
  • Padding and separators - zfill(), {:03d}, and {:,} handle leading zeros and thousands commas.
  • The reverse is int() - It parses digit strings back to integers and raises ValueError on anything else.

Converting numbers to text is one half of Python's type conversions. The other direction, parsing text into numbers, has its own edge cases, and the string to float lesson covers them.

Shivali Bhadaniya
About the author

Shivali Bhadaniya

I'm Shivali Bhadaniya, a computer engineer student and technical content writer, very enthusiastic to learn and explore new technologies and looking towards great opportunities. It is amazing for me to share my knowledge through my content to help curious minds. Connect on LinkedIn →