Convert int to string Python | Example code

Use the built-in str() function to convert int to string in Python. The str() function takes in any data type and converts it into a string object.

str(integer_value)

Example how to convert int to string Python

Simple example code converts int to str in python. Just pass int value into an str() function.

n = 100

res = str(n)

print(type(res), res)

Output:

Convert int to string Python

Alternative method

Use the “%s” keyword, the format function, or using f-string function.

num = 100

# % Operator
print(type("% s" % num))

# format() function
print(type("{}".format(num)))

# f-strings
print(type(f'{num}'))

Do comment if you have any doubts and suggestions on this Python integer to string code.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.