Concatenation is the process of joining two or more strings (or other compatible objects) into a single string — one of the most common and fundamental operations in Python. Whether building messages, constructing file paths, formatting logs, generating CSV rows, or cleaning text data, concatenation is everywhere. In 2026, efficient concatenation remains critical — especially in loops, large-scale text processing, data pipelines, and production code where performance, memory usage, and readability matter. Python offers multiple ways to concatenate, each with trade-offs in speed, clarity, and safety.
Here’s a complete, practical guide to concatenation in Python: basic + and +=, join() for efficiency, f-strings and .format() for formatting, real-world patterns, performance comparison, and modern best practices with type hints, safety, and scalability.
The simplest way is the + operator — it creates a new string by joining operands.
str1 = "Hello"
str2 = "world"
result = str1 + ", " + str2 + "!"
print(result) # Hello, world!
+= modifies the left operand in-place (for strings, it still creates a new string but is convenient for accumulation).
greeting = "Hello"
greeting += ", world!"
print(greeting) # Hello, world!
For concatenating many strings — especially in loops — use str.join() with a list — it’s much faster and more memory-efficient than repeated + or += (which can be quadratic time).
# Inefficient loop with +=
parts = ["Python", "is", "great", "for", "data", "science"]
s = ""
for word in parts:
s += " " + word
print(s.strip()) # Python is great for data science (slow for large lists)
# Efficient: list + join
parts = ["Python", "is", "great", "for", "data", "science"]
result = " ".join(parts)
print(result) # Python is great for data science
Formatting concatenation with f-strings (Python 3.6+) or .format() — clean, readable, and often faster than +.
name = "Alice"
age = 25
city = "New York"
# f-string (preferred)
print(f"{name} is {age} years old and lives in {city}.")
# .format() method
print("{} is {} years old and lives in {}.".format(name, age, city))
# Concatenation with str()
print(name + " is " + str(age) + " years old and lives in " + city + ".")
Real-world pattern: building CSV rows, log messages, or URLs — use join() for lists, f-strings for dynamic text.
# Build CSV row
fields = ["Alice", "25", "New York"]
csv_row = ",".join(fields)
print(csv_row) # Alice,25,New York
# Log message
level = "INFO"
message = "User login successful"
log_line = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {level}: {message}"
print(log_line)
Best practices make concatenation fast, safe, and readable. Prefer f-strings for formatting — f"{var}" is fastest, clearest, and type-safe. Use join() for multiple strings — never + or += in loops (quadratic time). Avoid += for strings in loops — use list accumulation + join(). Add type hints — str or list[str] — improves readability and mypy checks. Modern tip: use Polars for large text columns — pl.col("first") + " " + pl.col("last") or pl.concat_str(["first", " ", "last"]) is 10–100× faster than pandas. In production, use f-strings or .format() — avoid % operator (deprecated in favor of f-strings). Handle non-string types — use str() or f-strings — f"{num:.2f}" for floats. Combine with re for complex replacements — re.sub(r'\s+', ' ', text) for multiple whitespace.
Concatenation in Python is fast and flexible — + for simple joins, join() for lists, f-strings for formatting. In 2026, avoid loop concatenation, prefer f-strings and join(), vectorize in Polars/pandas, and add type hints for safety. Master concatenation, and you’ll build strings, logs, CSVs, URLs, and messages efficiently and elegantly.
Next time you need to join strings — reach for join() or f-strings. It’s Python’s cleanest way to say: “Put these pieces together.”