Convert number to string Python | Example code

Use the str() function to turn a number into a string in Python. This function takes an integer (or another type) as its input and produces a string as its output.

Example converting number to string Python

Simple example code.

num = 123
res = str(num)

print(type(res))

Output:

Convert number to string Python

Converts an integer to a string and appends it to the other string

# An integer version of year
year = 2021

# A string version of year
string_year = str(year)

# Concatinates the string with the string version of year
print("This is " + string_year + ".")

# Returns none if no argument is provided
print(str())

Output: This is 2021.

Do comment if you have any doubts and suggestions on this Python converting topic.

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.