Appending the same string to a list of strings in Python
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
Appending the same string to a Python list is simple, but the best expression depends on whether you want to mutate an existing list or create a new one. The good news is that strings are immutable, which makes some shorthand patterns completely safe here even though the same patterns would be dangerous for mutable inner objects.
Append Repeated Strings to an Existing List
If you already have a list and want to add the same string several times, use extend with list multiplication:
Output:
This is usually clearer than writing a manual loop when every appended value is identical.
Build a New Repeated List
If you do not need to preserve an existing list object, create the repeated list directly:
This is the simplest form when the list is just repeated string content.
Use a Loop Only When the Logic Changes Per Item
A loop is still appropriate when each element depends on iteration state:
If every appended value is exactly the same, the loop usually adds noise rather than clarity.
Why List Multiplication Is Safe for Strings
Python list multiplication has a bad reputation because it can duplicate references to mutable inner objects. That warning is real, but strings are immutable, so it does not apply here.
Safe with strings:
Problematic with inner lists:
In the second example, all three positions reference the same inner list. With strings, reassigning one element does not mutate a shared string object, so the pattern is safe.
append vs extend
This distinction matters:
Output:
Now compare extend:
Output:
Use append when adding one element. Use extend when adding several elements from an iterable.
A Small Helper Function
If the pattern appears often, wrapping it can make the intent explicit:
This version returns a new list instead of mutating the caller's list, which can be useful in codebases that avoid side effects.
When You Do Not Need a List at All
Sometimes the real need is not to store repeated strings, but to iterate over them once. In that case, a generator can avoid building a large list:
That is not an append operation anymore, but it is useful when the repeated values are only streamed.
Common Pitfalls
- Writing a manual loop for a repeated constant value when
extend([text] * n)already expresses the intent clearly. - Confusing
appendandextendand accidentally adding a whole list as one element. - Avoiding list multiplication because of mutable-object warnings even though strings are safe here.
- Forgetting to validate counts in helper functions, which can hide bad input.
- Building a huge repeated list when a generator would be enough for one-pass consumption.
Summary
- Use
extend([text] * n)to append the same string to an existing list. - Use
[text] * nwhen creating a new repeated list. - Strings are immutable, so list multiplication is safe for this case.
- Use loops only when per-item logic differs.
- Consider generators when you need repeated values without storing a large list in memory.
Related reading
- Applications of red-black trees
- Are arrays passed by value or passed by reference in Java?
- Are AVL trees evil?
- Are decision trees e.g. C4.5 considered nonparametric learning?
- Appending to an empty DataFrame in Pandas?
- Application not picking up .css file flask/python
- Are dictionaries ordered in Python 3.6?
- Are interval, segment, Fenwick trees the same?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.