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

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)


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

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

Note: IDE: PyCharm 2021.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 *

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