In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string. But use of the str() is not the only way to do so. This type of conversion can also be done using the “%s” keyword, the .format function or using f-string function.
Below is the list of possible ways to convert an integer to string in python:
1. Using str() function
Syntax: str(integer_value)
Example:
Python3
num = 10# check and print type of num variableprint(type(num))# convert the num into stringconverted_num = str(num)# check and print type converted_num variableprint(type(converted_num)) |
2. Using “%s” keyword
Syntax: “%s” % integer
Example:
Python3
num = 10# check and print type of num variableprint(type(num))# convert the num into string and printconverted_num = "% s" % numprint(type(converted_num)) |
3. Using .format() function
Syntax: ‘{}’.format(integer)
Example:
Python3
num = 10# check and print type of num variableprint(type(num))# convert the num into string and printconverted_num = "{}".format(num)print(type(converted_num)) |
4. Using f-string
Syntax: f'{integer}’
Example:
Python3
num = 10# check and print type of num variableprint(type(num))# convert the num into stringconverted_num = f'{num}'# print type of converted_numprint(type(converted_num)) |
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


