How to Convert Int to String in Python

When programming in Python, avoid “TypeErrors” by transforming an integer to a string. For example, by converting numbers into strings you can easily align the outcomes into a table. Another example is to concatenate a number prior to a string to identify a product. You use the “str” function to transform an integer to a string.

Converting Int to String in Python

python logo

  1. Open your Python editor.
  2. Type “str (number)”
  3. Press “Enter”. This runs the string function to convert an integer to a string.
  4. In the example below, you trigger the user to enter an number. Use the “int” function to convert the number to an integer. Add 5 to the integer. Then, the “str” function converts the integer to a string so that Python can concatenate and print out the response.
  5. “print (“Get in an integer:”,) response = input ()
  6. number = int (answer) addFive = number +5
  7. print (“Adding 5 to your number, we get the response” +str (addFive))”
  8. If you do not use “str” to transform the integer to a string, Python will provide you the mistake “TypeError: can not concatenate “str” and “int” things”.