In Python, you can convert an integer to a string using the str()
function or by using string formatting.
In this example,
42
to a variable named num
.str()
function to convert the integer num
to a string and store the result in the variable strNum
.str()
function converts the integer to its string representation.# Convert Integer to String using str() Function
num = 42
strNum = str(num)
print('String representation of integer:', strNum)
String representation of integer: 42
In this example,
-10
to a variable named negativeNum
.negativeNum
to a string and store the result in the variable strNegativeNum
.# Convert Negative Integer to String using String Formatting
negativeNum = -10
strNegativeNum = 'String representation of negative integer: {}'.format(negativeNum)
print(strNegativeNum)
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in Python language with well detailed examples.