How To Append A String In Python

2 min read

A beginner's first instinct when they want to append a string in Python is to look for an .append() method, the way lists have one. Also, strings do not work that way. So python strings are immutable, which means every time you add text to a string, you are not modifying the original at all — you are building a brand new string and pointing your variable at it. Once you understand that single idea, the six or seven techniques for appending strings stop feeling like random tricks and start making sense as tools with clear jobs. This guide walks through each one, explains when to use it, and shows the performance traps that catch almost everyone at least once It's one of those things that adds up..

Why Appending a String in Python Is Not What You Expect

Strings Are Immutable Objects

In Python, a str object cannot be changed after it is created. There is no append, insert, or extend method on a string. If you try, you get a clear error:

text = "Hello"
text.append(" world")
# AttributeError: 'str' object has no attribute 'append'

You can prove immutability yourself by watching the object's memory address change:

text = "Hello"
original_id = id(text)

text += " world"

print(text)                      # Hello world
print(id(text) == original_id)   # False

The address is different because text now refers to a completely new object. The old "Hello" object still exists somewhere in memory until Python's garbage collector reclaims it. This is the scientific explanation behind every performance issue discussed later in this article: **appending to a string always allocates new memory and copies every existing character.

Honestly, this part trips people up more than it should.

The Main Ways to Append a String in Python

1. The + Operator

The most readable option for joining two or a few strings:

first_name = "Ada"
last_name = "Lovelace"

full_name = first_name + " " + last_name
print(full_name)  # Ada Lovelace

Use + when the operation happens once and the pieces are few. Keep in mind that both operands must be strings, or Python raises a TypeError:

count = 3
message = "You have " + str(count) + " messages"  # str() conversion required

2. The += Augmented Assignment

+= looks like in-place appending, and syntactically it is the shortest way to extend a variable:

text = "Python"
text += " is"
text += " fun"
print(text)  # Python is fun

Under the hood, text += " is" is roughly text = text.Worth adding: __add__(" is"). It rebinds the name to a new string. It is perfectly fine for a handful of additions, but it becomes a problem inside loops The details matter here..

3. str.join() — The Professional Choice

When you have many pieces, collect them in a list and join them once:

words = ["Python", "is", "fun"]
sentence = " ".join(words)
print(sentence)  # Python is fun

# No separator at all
compact = "".join(["2026", "01", "15"])
print(compact)  # 20260115

join() performs a single allocation and a single copy pass. It is the idiomatic way to append many strings in Python, and it works with any iterable, including generators:

numbers = [1, 2, 
Still Here?

Just Went Live

Dig Deeper Here

A Natural Next Step

Thank you for reading about How To Append A String In Python. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home