How to Concatenate Strings in Python: 5 Methods with Examples
Five methods to concatenate strings in Python: +, join(), f-strings, format(), and %, with code examples, performance trade-offs, and placement round tips.
Python offers five ways to concatenate strings: the + operator, str.join(), f-strings, str.format(), and the % operator, each with different readability and performance characteristics.
String concatenation means joining two or more strings into one. It appears in Python example programs for formatting output, in web applications for building URLs, and in data-processing scripts for assembling structured text. This article covers all five methods with verified, runnable examples and clear guidance on when each one is the right call.
The + Operator
The + operator is the most direct approach. Place it between two string variables or literals and Python returns a new string containing both:
str1 = "FACE"
str2 = "Prep"
result = str1 + str2
print(result)
Output:
FACEPrep
Chaining works too, mixing string literals and variables freely:
result = "FACE" + " " + "Prep" + " Team"
print(result)
Output:
FACE Prep Team
The cost of + shows up inside loops. Python strings are immutable: every + call creates a fresh string object rather than extending the existing one. In a loop that accumulates a result over many iterations, intermediate objects pile up between each step until the garbage collector reclaims them. For a short expression joining two or three strings, + is perfectly readable. For loop-based accumulation, str.join() is the correct choice.
One more practical point: + does not coerce types. Trying to concatenate a string and an integer raises a TypeError. Convert first:
count = 42
message = "Total: " + str(count)
print(message)
Output:
Total: 42
str.join(): The Efficient Choice for Many Strings
str.join() takes an iterable of strings and joins them using the calling string as a separator. The Python documentation for str.join() specifies that every element in the iterable must be a string; passing non-string items raises a TypeError.
With an empty string as the separator, the result is a plain concatenation:
parts = ["FACE", "Prep"]
result = "".join(parts)
print(result)
Output:
FACEPrep
With a separator string, each element is joined by that separator:
words = ["Python", "string", "concatenation"]
result = " ".join(words)
print(result)
Output:
Python string concatenation
The pattern placement coding questions test most often is collect-then-join: build a list of parts across a loop, then call join() once at the end.
pieces = []
for i in range(5):
pieces.append(str(i))
result = "".join(pieces)
print(result)
Output:
01234
This avoids creating intermediate string objects on every loop iteration. The same reasoning applies to sorting a string alphabetically in Python: collect the sorted characters into a list, then join once.
"\n".join() is the right tool when the output needs one item per line, useful in coding problems that ask you to print a formatted list:
lines = ["Name: Arun", "Score: 95", "Rank: 1"]
output = "\n".join(lines)
print(output)
Output:
Name: Arun
Score: 95
Rank: 1
f-strings and str.format()
f-strings (Python 3.6+)
f-strings were introduced in PEP 498 and have been available from Python 3.6 onwards. An f prefix before a string literal allows expressions inside {} braces to be evaluated and embedded inline:
name = "Arun"
score = 95
message = f"{name} scored {score} in the coding test"
print(message)
Output:
Arun scored 95 in the coding test
No explicit type conversion is needed. f-strings call str() internally on embedded values, so integers and floats work without wrapping. Expressions also evaluate directly: f"Result: {2 + 3}" produces "Result: 5". For output-formatting tasks in placement coding rounds, f-strings are the most readable choice.
str.format()
str.format() predates f-strings and uses {} placeholders filled by positional or keyword arguments:
str1 = "FACE"
str2 = "Prep"
result = "{}{}".format(str1, str2)
print(result)
Output:
FACEPrep
Named placeholders add clarity in longer format strings:
result = "{brand} {product}".format(brand="FACE", product="Prep")
print(result)
Output:
FACE Prep
str.format() is common in codebases that still support Python 2/3 compatibility and in older competitive programming solutions. New Python 3.6+ code generally uses f-strings.
The % Operator
The % operator is Python’s original C-style string formatting syntax. The format string sits on the left; a tuple of substitution values goes on the right:
str1 = "FACE"
str2 = "Prep"
result = "%s%s" % (str1, str2)
print(result)
Output:
FACEPrep
%s substitutes a string, %d an integer, %f a float. You will encounter this pattern in legacy Python 2 codebases, textbook interview questions written before 2015, and some online judges that still use Python 2-era solutions. It is valid Python 3 syntax and runs correctly. It is simply not the preferred style for new code.
Which Method to Use
The choice depends on the task at hand:
| Method | Python version | Best for | Notes |
|---|---|---|---|
+ | All versions | Joining 2–3 strings in one expression | Avoid inside loops |
str.join() | All versions | Combining a list of strings | Single-pass; correct choice for loops |
| f-strings | 3.6+ | Embedding variable values into text | Most readable; no type conversion needed |
str.format() | 3.0+ | Template reuse; 2/3 compatibility | More verbose than f-strings |
% operator | All versions | Reading legacy code | C-style; not preferred for new code |
For questions that test checking character types in Python, string concatenation often appears as the last step: filter the characters, collect them into a list, then join them into the result string. str.join() fits that pattern cleanly.
Putting It Together
The five methods form a clear hierarchy. Use + for quick two-string joins in a readable single expression. Use str.join() when collecting parts across a loop. Use f-strings when embedding variable values into output. Keep str.format() and the % operator in your reading vocabulary for legacy code and older interview questions.
String manipulation is central to LLM application work too. Prompts are strings. Responses are strings. Every parsing step involves the same methods you just practiced. TinkerLLM puts direct LLM API access in your hands at ₹299. Building even one small prompt-formatting tool will make the str.join() vs + trade-off concrete in a way no textbook exercise can.
Primary sources
Frequently asked questions
What is the difference between join() and + for string concatenation in Python?
The + operator creates a new string object on every call, so concatenating n strings in a loop creates n intermediate objects. str.join() collects all parts in a list first and concatenates them in a single pass, which is more efficient when combining many strings.
Is f-string the fastest way to concatenate strings in Python?
For a small number of strings, f-strings and str.join() have similar performance. For combining a large list of strings, str.join() is the standard recommendation. f-strings are the preferred choice when you need to embed variable values into text for readability.
Can I concatenate a string and an integer in Python?
Not directly with +. Python raises a TypeError if you try str1 + 42. Convert the integer first using str(42), then concatenate. f-strings handle this inline: writing f'Score: {42}' works without explicit conversion.
What does str.join() raise if the list contains non-string items?
It raises a TypeError. All items in the iterable passed to join() must be strings. Convert non-string items to strings first using a generator expression: ''.join(str(x) for x in items).
Which string concatenation method should I use in a placement coding round?
Use + for joining two or three strings in a single expression. Use str.join() when building a result from a list of parts inside a loop. Use f-strings when embedding variable values into a sentence or formatted output.
What is the % operator in Python string formatting?
The % operator is Python's original C-style string formatting syntax. Using '%s%s' % ('FACE', 'Prep') produces 'FACEPrep'. It is still valid Python but f-strings and str.format() are now preferred in new code.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)