Python Program to Convert Integer to String

Write a Python program to convert integer to string. For example, in Python, we can use the built-in str function to convert int to string.

num = 120

print(num)
print(type(num))

intToString = str(num)

print(intToString)
print(type(intToString))
Python Program to Convert Integer to String

In this Python example, we use %s formatter to convert int to string.

num = int(input("Enter Any Number = "))

print(num)
print(type(num))

intToString = "%s" %num

print(intToString)
print(type(intToString))
Enter Any Number = 12313
12313
<class 'int'>
12313
<class 'str'>

Python program to convert integer to string using format function.

num = int(input("Enter Any Number = "))

print(num)
print(type(num))

intToString = "{}".format(num)

print(intToString)
print(type(intToString))
Enter Any Number = 2345
2345
<class 'int'>
2345
<class 'str'>

This python example uses the f to convert int to string.

num = int(input("Enter Any Number = "))

print(num)
print(type(num))

intToString = f'{num}'

print(intToString)
print(type(intToString))
Enter Any Number = 4567
4567
<class 'int'>
4567
<class 'str'>

In this Python example, we combined or showed all the possible options to convert int to string.

num = int(input("Enter Any Number = "))

print(num)
print(type(num))

print("\nResult of str function")
intToString = str(num)
print(intToString)
print(type(intToString))

print("\nResult of %s Formatter")
intToString1 = "%s" %num
print(intToString1)
print(type(intToString1))

print("\nResult of format function")
intToString2 = "{}".format(num)
print(intToString2)
print(type(intToString2))

print("\nResult of f string")
intToString3 = f'{num}'
print(intToString3)
print(type(intToString3))
Enter Any Number = 12345
12345
<class 'int'>

Result of str function
12345
<class 'str'>

Result of %s Formatter
12345
<class 'str'>

Result of format function
12345
<class 'str'>

Result of f string
12345
<class 'str'>