>>> str(42)
'42'

>>> int('42')
42

Links to the documentation:

  • int()
  • str()

str(x) converts any object x to a string by calling x.__str__(), or repr(x) if x doesn't have a __str__() method.

Answer from Bastien Léonard on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-integer-to-string-in-python
Convert Integer to String in Python - GeeksforGeeks
Explanation: format() places the integer inside the string placeholder {} and the returned value is a string. %s placeholder inserts values into a string and automatically converts them to string format.
Published: May 27, 2026
Discussions

Cannot use str() to convert an int to a string.
Is maxhealth and maxhunger also integers? print(f"\nHealth: {healthstat}/{maxhealth}") More on reddit.com
🌐 r/learnpython
13
23
January 18, 2022
How do I get an integer as a string?
Why is 10.0 printed For me it prints "10" (as it should). Perhaps some other part of your code or the environment is affecting what you see. More on reddit.com
🌐 r/learnpython
11
8
May 14, 2024
python - Short way to convert string to int - Stack Overflow
Maybe you were hoping for something like my_number = my_input.to_int. But it is not currently possible to do it natively. And funny enough, if you want to extract the integer part from a float-like string, you have to convert to float first, and then to int. More on stackoverflow.com
🌐 stackoverflow.com
Python: Convert a string to an integer - Stack Overflow
Does anybody have a quickie for converting an unsafe string to an int? The string typically comes back as: '234\r\n' or something like that. In this case I want 234. If '-1\r\n', I want -1. I ne... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

How to check if a string is an integer in Python?

To check if a string represents an integer, you can use the str.isdigit() method if the string contains only digits and no sign (+/-) or decimals:

string = "42"
if string.isdigit():
    print("The string is an integer.")
else:
    print("The string is not an integer.")

For strings that may include a sign (+/-), you can use a more robust method:

string = "-42"
try:
    int(string)
    print("The string is an integer.")
except ValueError:
    print("The string is not an integer.")
🌐
datacamp.com
datacamp.com › home › tutorials › python › how to convert a string into an integer in python
How to Convert a String Into an Integer in Python | DataCamp
What should I do if the string contains a decimal number and I want to convert it to an integer?

First, convert the string to a float using the float() function, then cast it to an integer using int(). For example:

decimal_string = "13.5"
converted_integer = int(float(decimal_string))
print(converted_integer)  # Output: 13
🌐
datacamp.com
datacamp.com › home › tutorials › python › how to convert a string into an integer in python
How to Convert a String Into an Integer in Python | DataCamp
🌐
SheCodes
shecodes.io › athena › 2142-converting-an-integer-to-string-in-python
[Python] - Converting an Integer to String in Python - | SheCodes
Learn how to convert an integer to a string in Python by using the `str()` function or casting the integer as a string.
🌐
Replit
replit.com › home › discover › how to convert an int to a string in python
How to convert an int to a string in Python | Replit
April 14, 2026 - The fix is to explicitly convert the integer to a string using the str() function. By wrapping age in str(age), you tell Python to treat the number as text. This allows the + operator to correctly concatenate all parts into a single string.
🌐
Mimo
mimo.org › tutorials › python › how-to-convert-integer-to-string-in-python
How to Convert Integer to String in Python
Learn how to convert an int to a string in Python with str() and f-strings, avoid TypeError, and build clean filenames and messages.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › cannot use str() to convert an int to a string.
r/learnpython on Reddit: Cannot use str() to convert an int to a string.
January 18, 2022 -

Okay, so I had a crash course in Python a looooong time ago, and that's all the prior experience I have with it. I'm starting to dabble in it again, playing around with it to make a text-based game.

In this game, you have stats - Speed, Health, etc etc. Each of these is a number (an int).

I am trying to define a function names statdisplay() so that when I call on it, it prints out your stats. So, if you have a Speed of 1, and the max Speed you can increase that stat to is 5, one of the printed lines would be:

Speed: 1 / 5

This was my ORIGINAL code:

 print("\nHealth: " + healthstat + " / " + maxhealth)
 print("\nHunger: " + hungerstat + " / " + maxhunger)

 print("\nStalking Skill: " + stalkingstat + " / 5")
 print("\nHunting Skill: " + huntingstat + " / 5")

 print("\nSpeed: " + speedstat + " / 5")
 print("\nStrength: " + speedstat + " / 5")

But then I got the following error:

TypeError: can only concatenate str (not "int") to str

So I mentally facepalmed myself and looked up how to convert an int to a string, and I keep reading that you can use the str() function (I know there are other ways, but I'm taking baby steps here trying to jog my memory on how everything works before I go doing everything by what's deemed "most appropriate").

This is my NEW code with that in mind:

 print("\nHealth: " + str(healthstat) + " / " + maxhealth)
 print("\nHunger: " + str(hungerstat) + " / " + maxhunger)

 print("\nStalking Skill: " + str(stalkingstat) + " / 5")
 print("\nHunting Skill: " + str(huntingstat) + " / 5")

 print("\nSpeed: " + str(speedstat) + " / 5")
 print("\nStrength: " + str(speedstat) + " / 5")

...and yet I am still getting the following error:

TypeError: can only concatenate str (not "int") to str

I can't seem to figure out what's wrong. I do not have the str() function defined as anything else. str() also doesn't seem to come from any special libraries that I'd need to import, but maybe I'm wrong there (I tried to look it up)... the only import I currently have is "import random".

My only other thought is that maybe it's a Google Colab thing, as that's where I'm currently running my code since this wasn't anything serious and I tend to go between two different computers.

Any help would be much appreciated!

Edit: accidentally had the new code in both code boxes.

🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.15.2 documentation
Return a pair of integers whose ratio is exactly equal to the original float. The ratio is in lowest terms and has a positive denominator. Raises OverflowError on infinities and a ValueError on NaNs. ... Two methods support conversion to and from hexadecimal strings. Since Python’s floats are stored internally as binary numbers, converting a float to or from a decimal string usually involves a small rounding error.
🌐
W3Schools
w3schools.in › python › examples › convert-int-to-string
Python Program to Convert Int to String
Using f-strings feature (available in Python 3.6 and above). Using % operator (also known as the "string formatting operator"). To convert an integer to a string in Python, the str() function can be used. This function takes an integer as an argument and returns the corresponding string ...
🌐
DataCamp
datacamp.com › home › tutorials › python › how to convert a string into an integer in python
How to Convert a String Into an Integer in Python | DataCamp
November 24, 2024 - When working with numerical data that are formatted as strings, it's often necessary to convert these strings into integers for calculations or other numerical operations. Python provides a straightforward way to achieve this using the int() function.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-integers-to-strings-in-python-3
How To Convert Integers to Strings in Python 3 | DigitalOcean
September 3, 2020 - We can convert numbers to strings using the str() method. In this quick tutorial, you’ll learn how to use this method to convert integers to strings.
🌐
Mimo
mimo.org › tutorials › python › how-to-convert-string-to-int-in-python
How to Convert String to Int in Python
Master Python from basics to advanced topics, including data structures, functions, classes, and error handling ... Start your coding journey with Python. Learn basics, data types, control flow, and more ... This approach is the right choice when the string represents a valid integer. ... This is a bad idea when the string contains non-numeric characters that cannot be converted.
🌐
FavTutor
favtutor.com › blogs › int-to-string-python
Convert Int to String in Python (6 Ways) | FavTutor
July 18, 2026 - In Python, the standard way to convert an integer to a string is the built-in str() function.
🌐
Unstop
unstop.com › home › blog › convert int to string in python (6 methods with examples)
Convert Int To String In Python (6 Methods With Examples)
April 11, 2024 - One common approach to convert int to string in Python is to use built-in functions like str(), which directly converts an integer to its string representation. For instance, str(123) returns the string '123'.
🌐
Facebook
facebook.com › groups › coding.beginner › posts › 2144590782570478
How to convert integer to string and string to integer in Python
Explore the things you love · Log into Facebook · English (US) · Español · Français (France) · 中文(简体) · العربية · Português (Brasil) · Italiano · More languages…
🌐
Andrea Corradini
pages.di.unipi.it › marino › python › Strings › ConvertinganIntegertoaStringinAnyBase.html
Converting an Integer to a String in Any Base using Recursion — Summarising How to Think like a Computer Scientist: Interactive Edition
Convert the single digit-number to a string using a lookup. Concatenate the single-digit strings together to form the final result. The next step is to figure out how to change state and make progress toward the base case. Since we are working with an integer, let’s consider what mathematical operations might reduce a number.