How to Convert a Value to a String in Python with str
str(value) turns any Python value into text: str(3) is "3", str(True) is "True" and str(None) is "None". You need it whenever you join a value to other text with +, because Python won't mix the two on its own.
Syntax
<text> = str(<value>)
| Part | What it does |
|---|---|
<value> | Any value: a number, a boolean, None, a list or an object of your own. |
str(...) | Returns the value as a string, in the form you'd normally print it. |
The Python documentation explains that str(object) returns type(object).__str__(object), "which is the "informal" or nicely printable string representation of object."
The Example
The example joins a number to text with str, converts a decimal number, a boolean, None and a list, and then tries to join text and a number without str.
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: Write the Code
Create a file named main.py:

count = 3
print("Apples: " + str(count))
print(str(2.5))
print(str(True))
print(str(None))
print(str([1, 2, 3]))
print("Apples: " + count)
Step 2: Run It
uv run python main.py
Apples: 3
2.5
True
None
[1, 2, 3]
Traceback (most recent call last):
File "/Users/Shared/you/main.py", line 7, in <module>
print("Apples: " + count)
~~~~~~~~~~~^~~~~~~
TypeError: can only concatenate str (not "int") to str
![A zsh terminal where uv run python main.py prints Apples 3, 2.5, True, None and [1, 2, 3], then a traceback ending in TypeError: can only concatenate str (not "int") to str.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/py-str-zsh.webp)
The command is the same in zsh, bash and PowerShell.
What Happened
"Apples: " + str(count)worked, because both sides were strings.- Every value had a text form.
strwrote the number, the boolean,Noneand the list the wayprintshows them. - The last line stopped the program.
"Apples: " + countasks Python to add a string and an integer, and it refuses withTypeError: can only concatenate str (not "int") to strrather than guessing what you meant.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Joining text and a number with + | TypeError: can only concatenate str (not "int") to str | Wrap the number in str(), or use an f-string |
Expecting str(None) to be an empty string | It's the four letters None | Check for None before converting |
| Converting a value to compare it with text | "3" == 3 is False in Python | Compare values of the same type |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
TypeError: can only concatenate str (not "int") to str | A number was joined to text with + | Convert it with str() |
The word None appears in your output | A variable held None when it was converted | Find where it should have been given a value |
FAQ
Does print need str?
No. print converts each value itself, which is why print(count) works. You need str() when you build the text yourself.
What's the difference between str and repr?
str gives the readable form and repr gives the form a programmer would type: str("hi") is hi, while repr("hi") includes the quotes.
Conclusion
str(value) turns any value into text. Use it whenever you join a value to other text with +.
Additional Resources
- str and the built-in functions, in the Python documentation.
