Skip to main content
Strings

How to convert an int to a string in Python

Quick answer

Use f'{num}' or str(num) to turn an integer into its string representation instantly.

num = 42
s1 = str(num)
s2 = f"{num}"
print(s1, s2)

The snippet assigns an integer to num, then creates two string versions: s1 using the built-in str() function and s2 using an f-string. Both produce a plain str object that can be concatenated, written to files, or passed to APIs; the final print shows they are identical.

Using the native str() or an f-string is the most direct, zero-dependency method. They handle any size integer, respect sign, and avoid the overhead of older %-formatting. A common gotcha is that booleans are subclasses of int, so str(True) yields "True"; if you need strict int handling, add an explicit isinstance check.

Variations

Using format() method

num = 42
s = "{}".format(num)
print(s)

Older style, works in all Python versions, but f-strings are clearer.

Safe conversion with type check

def safe_int_to_str(value):
    if isinstance(value, int):
        return str(value)
    raise TypeError("value must be int")
print(safe_int_to_str(7))

Raises explicit error if input is not an int, avoids accidental conversion of booleans.

Batch conversion of ints

ints = [1, 2, 3]
strs = [str(i) for i in ints]
print(strs)

List comprehension keeps conversion fast and readable.

Practise this in your browser

Every how-to has a live lesson. Free tier, no card.

Start free β†’

Unlock every lesson

Pro β€” $12/mo, unlimited AI, cancel any time.

See Pro plans β†’

Get one Python lesson + one career idea every Friday

No spam, no "buy our course now". Three bullets, every Friday. Unsubscribe with one click.

Related how-tos