How to Convert Int to String in Python
When programming in Python, avoid "TypeErrors" by converting an integer to a string. For example, by converting numbers into strings you can easily align the results into a table. Another example is to concatenate a number before a string to enumerate an item. You use the "str" function to convert an integer to a string.
Launch your Python editor.
Type "str (number)".
Press "Enter". This runs the string function to convert an integer to a string. In the example below, you prompt the user to enter an number. Use the "int" function to convert the number to an integer. Add five to the integer. Then, the "str" function converts the integer to a string so that Python can concatenate and print out the answer. "print ( "Enter an integer: ",)answer = input ()number = int (answer)addFive = number +5print ( "Adding 5 to your number, we get the answer " +str (addFive))"If you do not use "str" to convert the integer to a string, Python will give you the error "TypeError: cannot concatenate "str" and "int" objects".