Python: int to string – this is how it works

by Michaela

This page shows how you can easily convert an integer into a string (“int to string”) in Python. Because programming with Python is not that difficult.

Convert integer to string: Python guide

When programming with Python, an integer is used for an integer. However, sometimes you need to convert it to a string. For example, if you want to write the integer (as a number, for example) to a file.

  • You can easily convert an integer into a string with the function “str()”. Simply write a variable or an integer in the brackets. If the variable “a” has the value 3, for example, you can output this value as a string with the function “str(a)” (without inverted commas).
  • However, the whole thing also works the other way round: with the command “int()”, a value is output as an integer.
  • The function “float()” is also very practical. With it you can turn an integer or string into a floating point number.

     

Related Articles

Leave a Comment