Skip to content

Convert int to string Python | Example code

  • by

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.


Example how to convert int to string Python

A simple example code converts int to str in Python. Just pass the int value into str() function.

n = 100

res = str(n)

print(type(res), res)


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

# f-strings

If you want to concatenate an integer with a string, you can also use the str() function to convert the integer to a string and then use the + operator to concatenate the two strings.

age = 25
message = "I am " + str(age) + " years old."
print(message)  # Output: "I am 25 years old."

Comment if you have any doubts or suggestions on this Python integer-to-string code.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Your email address will not be published. Required fields are marked *