>>> 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
str() function is the simplest and most commonly used method to convert an integer to a string. ... Explanation: str(n) converts n to a string, resulting in '42'. For Python 3.6 or later, f-strings provide a quick way to format and convert values.
Published   July 12, 2025
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
Quick question: Is there a way to get the first three digits of a int without converting it to a string or list?

You probably shouldn't be keeping phone numbers as ints, because they don't behave like ints. You'll never add, subtract, multiply, or divide phone numbers. You will, however, access individual digits of them, so an array is a much more appropriate type. If you absolutely must store them as ints for efficiency reasons (unlikely), then at point of use you should probably just convert them, unless that is too expensive (even more unlikely).

Remember readability is generally more important than minor performance gains, so digits(num)[:3] is much easier to understand than (num-num%le6)/le6 as skier_scott suggests doing.

More on reddit.com
🌐 r/Python
36
16
January 4, 2013
How to convert scientific notation string to integer?
using an integer for scientific notation probably isn't what you want. Use a float. float('1.77e16') More on reddit.com
🌐 r/learnpython
5
1
November 6, 2022
Do you normally use string.format() or percentage (%) to format your Python strings?

Firstly, you can write e. g. {0:.2f} to specify a float with 2 decimals, see e. g. https://www.digitalocean.com/community/tutorials/how-to-use-string-formatters-in-python-3

Secondly, the best formatting method is f-strings, see e. g. https://www.blog.pythonlibrary.org/2018/03/13/python-3-an-intro-to-f-strings/

More on reddit.com
🌐 r/Python
130
75
June 3, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-string-to-integer-in-python
Convert String to Int in Python - GeeksforGeeks
The simplest way to convert a string to an integer in Python is by using the int() function.
Published   September 11, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-integers-string-to-integer-list
Python - Integers String to Integer List - GeeksforGeeks
July 15, 2025 - Using list comprehension allows you to create a new list by applying an expression to each element of an iterable. This method is compact and often more readable than traditional loops, making it ideal for transforming or filtering elements of a list or string. ... # Input string of integers s = "1 2 3 4 5" # Convert the string to a list of integers using list comprehension int_list = [int(i) for i in s.split()] # Print the result print(int_list)
Find elsewhere
🌐
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
February 6, 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.
🌐
Quora
quora.com › How-do-you-convert-int-to-string-without-using-an-in-built-function-in-Python-3-Python-Python-3-x-development
How to convert int to string without using an in-built function in Python 3 (Python, Python 3.x, development) - Quora
For negative numbers, using -n is safe in Python because ints are arbitrary precision; in languages with fixed-width integers you must handle INT_MIN specially. The iterative method is most straightforward and efficient for common use. These implementations produce standard base-10 decimal representations without leading zeros. ... The simple answer is you cannot convert an int to a string without using any builtin functions.
🌐
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.

🌐
Analytics Vidhya
analyticsvidhya.com › home › 6 methods to convert string to int in python
Top 6 Ways to Convert String to Int in Python
May 20, 2025 - Another method to convert a string to an integer is using the ast.literal_eval() function from the ast module. This function evaluates the given string as a Python literal and returns the corresponding value.
🌐
Flexiple
flexiple.com › python › convert-string-to-int
Python Convert String to Int - How to Cast a String in Python - Flexiple
Here, the float() function converts the string "123.45" to a floating-point number, which is then converted to an integer 123 using the int() function, truncating the decimal part. The eval() function evaluates the “stringified” version of Python expressions, which can include numeric conversions.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-strings-to-integers-in-python-3
How To Convert Strings to Integers in Python 3 | DigitalOcean
September 3, 2020 - Let’s modify the code to include the int() method that will convert the strings to integers, and allow us to do math with these values that were originally strings. lines_yesterday = "50" lines_today = "108" lines_more = int(lines_today) - int(lines_yesterday) print(lines_more) ...
🌐
AlgoCademy
algocademy.com › home › string to int in python: a comprehensive guide
String to Int in Python: A Comprehensive Guide - AlgoCademy Blog
February 13, 2025 - Always validate input: Check if the string represents a valid integer before conversion. Use try-except blocks: Handle potential ValueError exceptions to gracefully manage conversion errors. Consider the context: Choose the appropriate base (e.g., decimal, binary, hexadecimal) based on your data source and requirements. Handle edge cases: Account for negative numbers, leading/trailing whitespace, and empty strings. Use type hints: Employ Python’s type hinting system to clarify expected input and output types.
🌐
Codemia
codemia.io › knowledge-hub › path › convert_integer_to_string_in_python_1
Convert integer to string in Python
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
W3Schools
w3schools.com › python › python_casting.asp
Python Casting
Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. Casting in python is therefore done using constructor functions: int() - constructs an integer number from an integer literal, a float literal (by removing all decimals), or a string literal (providing the string represents a whole number)
🌐
Python Geeks
pythongeeks.org › python geeks › learn python › convert string to int in python
Convert String to int in Python - Python Geeks
December 31, 2025 - Converting a string to an integer is a common operation in Python, and it can be done easily using the int() function. In this article, we learned what the int() function is and how it works.
🌐
CodeOp
codeop.tech › home › uncategorized › python int to string and other conversions – a beginner’s guide
Python Int to String and Other Conversions - A Beginner's guide - CodeOp
March 27, 2025 - You can’t directly add an integer with a string because they’re vastly different data types. So, for this, you’ll have to either do explicit conversion or use a formatted string.
🌐
W3Schools
w3schools.com › python › ref_func_int.asp
Python int() Function
The int() function converts the specified value into an integer number. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
Kanaries
docs.kanaries.net › topics › Python › covnert-string-to-int-python
How to Convert String to Int in Python: Easy Guide – Kanaries
August 16, 2023 - In this essay, we will explore type casting, built-in functions, and error-handling techniques to effectively convert strings to integers in Python.