String concatenation means building one string from pieces: literals, variables, or slices of other strings. Python offers +, f-strings, str.join, and +=. This guide follows a quick answer, each technique, when to prefer which, common mistakes, a cheat sheet, and a short summary.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic.
Quick answer: concatenate strings in Python
For a few pieces, use + or an f-string. For many pieces already in a list, use "".join(parts) (or another separator as the method receiver). For more on older str.format, see Python string format. For appending to an existing variable in a loop, see append string in Python.
a, b = "hello", "world"
print(a + " " + b)
print(f"{a} {b}")
print(" ".join([a, b]))What is string concatenation in Python?
Concatenation produces a new str object; original strings are not mutated (strings are immutable). Each + or slice-based build allocates a new string holding the combined text.
s = "py" + "thon"
print(s, len("py") + len("thon") == len(s))Concatenate strings using + operator
+ joins two strings end to end. It is clear for two or three fragments and avoids a call to join when you do not already have a list.
greeting = "Hi, " + "Alex" + "!"
print(greeting)Add space while concatenating strings
+ does not insert spaces; put them inside the literals or build them explicitly.
first = "Jane"
last = "Doe"
print(first + " " + last)
print(first, last) # print adds a space between argumentsConcatenate string and variable in Python
Use + with every piece as a str, or use an f-string so values are formatted in place.
name = "Sam"
age = 30
print("Name: " + name + ", age: " + str(age))
print(f"Name: {name}, age: {age}")Concatenate multiple strings in Python
Chain +, use "".join((a, b, c)), or build a list and join once. Parentheses help readability on long chains.
parts = ("one", "two", "three")
print(", ".join(parts))Concatenate strings using f-strings
Formatted string literals (f"...") embed expressions in {...}. They are usually the most readable way to mix text and variables in Python 3.6+.
user = "dev"
lines = 42
print(f"{user} pushed {lines} lines today")Concatenate strings using join()
str.join is called on the separator string and takes an iterable of strings. It is the idiomatic way to combine many parts with a delimiter—the complement of Python split string.
Join a list of strings
words = ["python", "concatenate", "strings"]
print("".join(words))
print(" ".join(words))Join strings with separator
path_bits = ("home", "user", "doc.txt")
print("/".join(path_bits))Non-string values in the iterable raise TypeError; convert first (str(x)).
Concatenate strings using += operator
+= on a string name rebinds it to a new string each time (s = s + other). For a few appends it is fine; in a long loop it can be slower than accumulating a list and joining once.
msg = "start"
msg += " + middle"
msg += " + end"
print(msg)+ vs f-string vs join(): which one should you use?
| Situation | Prefer |
|---|---|
| Two or three literals or variables | + or f-string |
| Several values with formatting | f-string |
| Many pieces already in a list | str.join |
| Building inside a tight loop | list + join, or io.StringIO |
| Legacy code without f-strings | str.format or % (discouraged for new code) |
Common mistakes in Python string concatenation
These are the issues that show up most often in code review and in tracebacks: spacing is easy to forget with +, mixing numeric types with + raises TypeError, and growing a string in a loop scales poorly. Each subsection states the symptom, shows a minimal fix, and notes when the cost actually matters.
Missing space between strings
+ glues bytes exactly as written. Two literals "foo" and "bar" become "foobar" unless you insert a space literal, a variable that already contains trailing space, or switch to print(a, b) / an f-string with an explicit space in the template.
print("foo" + "bar") # foobar
print("foo" + " " + "bar")For dynamic pieces, build spacing into the data (first + " " + last) or use an f-string: f"{first} {last}".
Concatenating string with number
The + operator is only defined between two strings. Integers, floats, and other types must be converted first, or you should skip + entirely and let an f-string or str.format handle the conversion for you.
count = 7
# print("items: " + count) # TypeError
print("items: " + str(count))
print(f"items: {count}")str(count) is explicit; f"items: {count}" is usually clearer when several values are involved.
Using + inside loops for many strings
Each += on a string creates a new string object and copies the old contents forward, so the work grows like roughly O(n²) when you append many growing pieces. A few iterations is harmless; thousands or millions of rows from a file or database is where join, a list comprehension plus one join, or io.StringIO pays off.
# slower pattern for large n
s = ""
for i in range(5):
s += str(i)
# usually better for many parts
parts = [str(i) for i in range(5)]
t = "".join(parts)
print(s, t)For small n, either version is readable—choose clarity first. When profiling shows a hot path, collect fragments in a list (or write to io.StringIO) and materialize one final string at the end.
Python string concatenation quick reference table
| Technique | Example | Notes |
|---|---|---|
+ |
"a" + "b" |
No auto spaces; both sides must be str |
| f-string | f"{x}{y}" |
Embeds expressions; readable |
join |
",".join(xs) |
xs must be strings |
+= |
s += "x" |
Repeated use in huge loops can be costly |
print |
print(a, b) |
Adds spaces between arguments, not true concatenation |
Summary
Concatenation builds new strings: use + for tiny joins, f-strings when variables and formatting dominate, and str.join when you have many segments (especially from a list). Add spaces explicitly with + or use print’s multi-argument form for human spacing. Convert numbers with str(...) or f-strings before combining with +. Avoid growing strings with += inside hot loops; batch with join. For broader Python context, see beginner tips for Python.

