Append String in Python

Learn how to append to a string in Python using +, +=, f-strings, format(), and join(). Understand why Python strings have no append() method and when to use each approach.

Published

Updated

Read time 6 min read

Reviewed byDeepak Prasad

Append String in Python

Python strings do not have an append() method like lists. Strings are immutable, so appending text means creating a new string from the old string plus the new text.

Tested on: Python 3.13.3; kernel 6.14.0-37-generic.


Quick answer: append to a string in Python

Use text += "more" for simple appending. Use text = text + "more" for explicit concatenation. Use f-strings when appending variables into a sentence. Use "".join(parts) when combining many strings.

python
text = "Hello"
text += " World"
print(text)

name = "Deepak"
age = 32
print(f"My name is {name} and I am {age} years old.")
Output

The first block appends literal text. The f-string builds a message with variables in one readable expression.


Python append string quick reference

Task Use
Append one string text += " world"
Concatenate two strings result = a + b
Append with space result = a + " " + b
Append variable in text result = f"{name} is {age}"
Append non-string value result = text + str(value)
Join many strings result = "".join(parts)
Join with separator result = " ".join(words)
Build string in loop collect parts in list, then "".join(parts)
Append newline text += "\n" + line
Efficient file-like string building io.StringIO
Method that does not exist str.append()

Does Python have a string append() method?

No. Python strings do not have append(). append() is a list method, not a string method.

Strings are immutable. Any append-like operation creates a new string and assigns it to a variable. The original string object is not modified in place.

python
text = "Hello"
text += " World"
print(text)

# This fails — strings have no append()
try:
    "Hello".append(" World")
except AttributeError as exc:
    print(type(exc).__name__)
Output

Append to a string using +=

+= is the most direct way to append a small string. It is shorthand for text = text + new_text. For a broader look at joining techniques, see Python concatenate strings.

python
message = "Hello"
message += " World"
print(message)
Output

Good for simple cases. Remember that Python assigns a new string value; it does not mutate the old string object in place.


Append strings using + operator

+ joins two strings. It does not add spaces automatically, and both operands must be strings.

python
first = "Hello"
second = "World"
result = first + " " + second
print(result)

age = 32
print("Age: " + str(age))
Output

Use str() when you need to append integers, floats, or other non-string values.


Append variables using f-strings

f-strings are usually the cleanest way to build readable strings with variables. They work well for sentences, messages, logs, and labels.

python
name = "Deepak"
age = 32

message = f"My name is {name} and I am {age} years old."
print(message)

count = 5
print(f"Count: {count}")
Output

f-strings were introduced in Python 3.6 and are the preferred choice for most new code.


Append strings using format()

str.format() is useful for older code or when you prefer template-like formatting. It is still valid, but f-strings are usually cleaner in Python 3.6+.

python
name = "Deepak"
age = 32

message = "My name is {} and I am {} years old.".format(name, age)
print(message)
Output

Keep format() for codebases that already use it consistently or when you need reusable format templates.


Append many strings using join()

join() is best when you already have a list or iterable of strings. The separator string goes before .join().

python
words = ["Hello", "World"]
numbers = ["1", "2", "3"]

print(" ".join(words))
print("".join(numbers))
Output

"".join(parts) joins without a separator. " ".join(words) joins with spaces. Every item must be a string, or Python raises TypeError.


Append string in a loop

For a small loop, += is usually fine. For many pieces, collect strings in a list and use "".join(parts) at the end.

python
# Small loop — += is fine
result = ""
for i in range(5):
    result += str(i)
print(result)

# Many pieces — list + join is clearer
parts = []
for word in ["Python", "string", "append"]:
    parts.append(word)
sentence = " ".join(parts)
print(sentence)
Output

The list approach avoids repeatedly building large temporary strings in memory.


Append string with separator

Use + when manually adding a separator between a few strings. Use join() when appending many items with the same separator.

python
tags = ["python", "strings", "tutorial"]

csv_manual = tags[0] + "," + tags[1] + "," + tags[2]
csv_join = ",".join(tags)

print(csv_manual)
print(csv_join)
Output

join() scales better for comma-separated values, space-separated words, and similar patterns.


Append newline to a string

Use "\n" when appending a single new line. For many lines, collect lines in a list and use "\n".join(lines).

python
report = "Summary"
report += "\n" + "Line 1"
report += "\n" + "Line 2"
print(report)

lines = ["Error: timeout", "Warn: retry", "Info: done"]
log = "\n".join(lines)
print(log)
Output

Useful for reports, logs, and generated text output.


Append non-string values to a string

Python cannot concatenate str and int directly. Convert values with str(), or use f-strings for readability.

python
count = 42
price = 19.99

print("Count: " + str(count))
print(f"Price: {price:.2f}")
Output

f-strings handle conversion for you inside {...} expressions.


Append string to a list vs append to a string

Task Method
Add string as an item in a list my_list.append("text")
Add text to an existing string text += "text"
Combine list of strings into one string "".join(my_list)
python
items = []
items.append("first")
items.append("second")
print(items)

text = "start"
text += " end"
print(text)

print(" ".join(items))
Output

list.append() changes the list in place. String appending creates a new string value.


Append bytes vs append string

Strings and bytes are different types. Do not concatenate str and bytes directly.

python
text = "Hello"
data = b" World"

combined = text + data.decode("utf-8")
print(combined)

encoded = (text + " World").encode("utf-8")
print(encoded)
Output

Decode bytes to str, or encode str to bytes, before combining them.


Which method should you use?

Situation Recommended method
Add two simple strings +
Add text to existing variable +=
Build a message with variables f-string
Support older Python code format()
Combine list of strings join()
Build many lines list + "\n".join(lines)
Very large streaming text io.StringIO

For large streaming builds, io.StringIO behaves like an in-memory text buffer:

python
import io

buffer = io.StringIO()
buffer.write("Line 1\n")
buffer.write("Line 2\n")
print(buffer.getvalue())
Output

Summary

Python strings do not have append(). Use += or + for simple appending, f-strings for messages with variables, and join() for many strings. Convert non-string values before concatenating, or use f-strings. For list operations, use list.append(). For splitting strings apart, see Python split string.


References


Frequently Asked Questions

1. Does Python have a string append() method?

No. str has no append() method because strings are immutable. Use +=, +, f-strings, format(), or join() to build a new string instead.

2. What is the easiest way to append to a string in Python?

Use text += "more" for simple appending. It is shorthand for text = text + "more" and assigns a new string value.

3. When should you use join() instead of +=?

Use join() when you already have many strings in a list or when building text in a loop with many pieces. It avoids repeated temporary string creation.

4. Can you append an integer to a string in Python?

Not directly. Convert the value with str() or use an f-string such as f"Count: {count}".

5. What is the difference between list.append() and appending to a string?

list.append() adds an item to a list in place. Appending to a string means creating a new string because strings cannot change after creation.

6. Are f-strings better than format() for appending variables?

In Python 3.6 and later, f-strings are usually the clearest choice for readable messages with variables. format() is still useful in older code or template-style formatting.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …