Python string concatenation is most often done with the + operator for two or three pieces, with an f-string when you mix text and values, and with "".join(...) when you combine many strings from a list or loop. Strings are immutable in Python, so every concatenation builds a new string object rather than changing an existing one.
This article covers each approach on Python 3.13 and 3.14, shows when each one is the right tool, and explains the common TypeError you get when you try to add a string and a number.
The + operator takes two strings and returns a new string that holds the characters of the left side followed by the characters of the right side.
The space is its own string, because + adds nothing between the pieces. The augmented form += is a shortcut for text = text + other:
Two string literals written next to each other are joined by the compiler before the program runs, with no operator at all:
This only works for literals, not for variables. It is mainly useful for splitting a long literal across lines inside parentheses.
Python does not convert types silently when you use +. Mixing a string with an integer raises a TypeError:
You can convert the number first with str(), but an f-string is usually cleaner:
An f-string (formatted string literal) starts with f before the opening quote. Anything inside {} is evaluated as an expression and converted to text. This is the standard way to put values into a sentence.
After the colon you can add a format specifier such as .1f for one decimal place. The !r conversion applies repr(). Since Python 3.12 you can reuse the same quote type inside the braces and spread an f-string over several lines, which removes most of the old workarounds. For most mixed text-and-value cases, an f-string is easier to read than a chain of + and str() calls.
When you have a list, tuple or other iterable of strings, call join() on the separator string:
Every item must already be a string. If your list has numbers, convert them inside a generator expression:
Because strings are immutable, result += piece inside a loop can copy the growing string on every pass. CPython has an optimisation that often hides this cost for simple cases, but it is an implementation detail and not guaranteed, and other Python implementations do not have it. The portable pattern is to collect the pieces in a list and join once:
| Method | Example | Best for |
|---|---|---|
+ | a + b | Two or three short strings |
+= | s += x | A few appends, not large loops |
| f-string | f"{a} {b}" | Mixing text and values |
str.join | ", ".join(items) | Many strings from an iterable |
print(a, b, sep="") | print("a", "b", sep="") | Output only, no new string |
str.format | "{} {}".format(a, b) | Templates stored separately from the values |
The older % operator ("%s %s" % (a, b)) still works but f-strings and format() are preferred in new code.
Bytes and strings cannot be mixed either. b"abc" + "def" raises a TypeError; decode the bytes with .decode() first. Lists of characters are joined the same way as lists of words, for example "".join(["a", "b", "c"]) gives "abc".
For many pieces, str.join on a list is the fastest and most portable choice. For two or three strings the difference is negligible, so pick the form that reads best.
Not with +. Convert the integer with str() or put it in an f-string, such as f"Total: {total}".
In a small number of appends it is fine. In a large loop it can become quadratic on some Python implementations, so collect pieces in a list and call join() once.
Wrap adjacent string literals in parentheses, or use a triple-quoted string. Adjacent literals are joined at compile time.
Use + for a couple of strings, an f-string when you combine text with values, and "".join(items) when you build a string from many parts. Strings are immutable, so each concatenation creates a new object, and mixing a string with a number requires an explicit conversion.