Learn · Run · Break · Fix
A learning series from A Wandering Mind
Eighteen interlinked lessons on strings, lists, files, exceptions, and dictionaries—with original explanations, runnable examples, real output, and supporting CPSC 1301K lectures.
>>> guide = { ... "lessons": 18, ... "modules": 5, ... "python": "3.10+" ... } >>> guide["goal"] = "understand it"
Combining and Repeating Lists in Python
Python lets list operators describe two useful sequence operations directly. The + operator concatenates lists by placing one sequence after another, while * repeats a list a whole number of times. These operators look familiar from arithmetic, but with lists their meaning is about sequence structure rather than numeric addition or multiplication.
Concatenation places one list after another
When both operands are lists, the + operator performs concatenation. Python creates a new list containing the items from the list on the left followed by the items from the list on the right. It does not add corresponding values together, and it does not automatically change either original list.
This is the same broad idea you saw with strings: combining "Py" and "thon" produces "Python". With lists, the units being combined are list elements instead of characters. Order is preserved, so the entire left-hand sequence appears before the right-hand sequence.
morning = ["coffee", "email"]
afternoon = ["meeting", "walk"]
day = morning + afternoon
print(day)
print(morning)
['coffee', 'email', 'meeting', 'walk']
['coffee', 'email']
The first output shows the new combined list. The second proves that morning was not changed by the expression. That distinction matters after Lesson 5, where assignment, del, remove(), and pop() all changed an existing list. Plain list concatenation with + instead produces another list value.
Think “sequence after sequence.” For lists, left + right means “all items from left, followed by all items from right.” It does not mean pairwise arithmetic.
The order of concatenation matters
Because lists are ordered, reversing the operands changes the result. If a = [1, 2] and b = [3, 4], then a + b produces [1, 2, 3, 4], while b + a produces [3, 4, 1, 2]. The same elements appear, but the sequence is different.
This makes concatenation useful for assembling larger collections from sections. A navigation menu might begin with core destinations and then add optional destinations. A report might join a header row, data rows, and a footer row. The operation is simple, but the position of each source list communicates structure.
Repetition copies the sequence pattern
The * operator repeats a list when the other operand is an integer. If a two-item list is multiplied by 3, Python returns a six-item list containing the original two-item pattern three times in order. Again, this is sequence behavior rather than arithmetic performed on the individual elements.
pattern = ["red", "blue"]
repeated = pattern * 3
print(repeated)
print(len(repeated))
['red', 'blue', 'red', 'blue', 'red', 'blue']
6
The original list has length two. Repeating the entire sequence three times produces six elements, which len() confirms. This connects directly to Lesson 4: repetition changes the length of the result because it changes how many elements appear in the new sequence.
Combine operators to build predictable structures
Concatenation and repetition become more useful when they are treated as building blocks. You might concatenate two meaningful groups and separately use repetition to create placeholders, defaults, markers, or a short repeated pattern. The resulting lists can then be indexed, modified, looped over, or sliced in later lessons.
core = ["home", "search"]
extras = ["profile", "settings"]
navigation = core + extras
placeholders = ["pending"] * 2
print(navigation)
print(placeholders)
['home', 'search', 'profile', 'settings']
['pending', 'pending']
The first expression assembles one four-item navigation list from two smaller groups. The second creates two identical placeholder values without manually writing "pending" twice. These are small examples, but the pattern scales: code can describe how a structure is assembled instead of spelling out every repeated element.
Zero and one reveal how repetition behaves
Two edge cases are especially useful for understanding the operator. Multiplying a list by 1 returns a list with the same sequence of elements. Multiplying by 0 returns an empty list because the source sequence is repeated zero times. Concatenating an empty list similarly contributes no elements.
items = ["a", "b", "c"]
print(items + [])
print(items * 1)
print(items * 0)
['a', 'b', 'c']
['a', 'b', 'c']
[]
These examples are useful when reading unfamiliar code. items + [] contributes nothing from the right side. items * 1 keeps one repetition of the sequence. items * 0 keeps none. Negative repetition counts also produce an empty list, though using a negative value intentionally is uncommon and can make the code less obvious to a beginner.
a + bReturns a new list containing all of a, then all of b.
a * 3Returns the sequence in a three times.
a * 1Returns one repetition of the sequence.
a * 0Returns an empty list.
The operands still have to be compatible
The symbols + and * do not mean that Python will combine arbitrary types automatically. List concatenation expects another list. List repetition expects an integer repetition count. If the types do not fit the sequence operation, Python raises a TypeError rather than guessing what conversion you intended.
This is an important programming habit: read an operator in the context of the types around it. The same + symbol can add numbers, concatenate strings, or concatenate lists. Python decides which behavior is available from the objects involved.
Common mistakes with list operators
Every failure below was executed. Notice that all four are TypeError cases, but the messages differ because each expression violates a different operand rule.
items = ["a", "b"]
print(items + "c")
Traceback (most recent call last):
File "/tmp/awm_lesson6/mistake1_list_plus_string.py", line 2, in <module>
print(items + "c")
~~~~~~^~~~~
TypeError: can only concatenate list (not "str") to list
Python will not interpret "c" as a one-item list. If you want another list element in a concatenation expression, write a list such as ["c"]. The container type matters.
items = ["a", "b"]
print(items * 2.5)
Traceback (most recent call last):
File "/tmp/awm_lesson6/mistake2_list_times_float.py", line 2, in <module>
print(items * 2.5)
~~~~~~^~~~~
TypeError: can't multiply sequence by non-int of type 'float'
A sequence cannot appear two and a half times. Repetition therefore requires an integer count. If your program calculated a floating-point value, decide explicitly how that value should become a whole number before using it as a repetition count.
label = "Items: "
items = ["a", "b"]
print(label + items)
Traceback (most recent call last):
File "/tmp/awm_lesson6/mistake3_string_plus_list.py", line 3, in <module>
print(label + items)
~~~~~~^~~~~~~
TypeError: can only concatenate str (not "list") to str
The left side is a string, so Python interprets + as string concatenation and expects another string. If your goal is readable output, an f-string such as f"Items: {items}" is clearer and connects back to Lesson 1.
items = ["a", "b"]
print(items * "3")
Traceback (most recent call last):
File "/tmp/awm_lesson6/mistake4_repeat_wrong_operand.py", line 2, in <module>
print(items * "3")
~~~~~~^~~~~
TypeError: can't multiply sequence by non-int of type 'str'
The characters "3" represent text, even though they look like a number. List repetition needs the integer 3. This is another example of why values that look similar on screen can behave very differently when their Python types differ.
Supporting classroom explanations
This page is original A Wandering Mind instructional material. The two CPSC 1301K lectures below provide additional classroom explanations of the two operators used throughout this lesson.
What it adds: a classroom walkthrough of using the + operator to place list sequences together while preserving their order.
What it adds: a focused explanation of sequence repetition and how integer repetition counts affect the resulting list.
Try it yourself
Predict the complete list before running each answer. The goal is to become comfortable reading + and * as sequence operations rather than defaulting to their arithmetic meanings.
Exercise 1 · Join two directions lists
Create first = ["north", "south"] and second = ["east", "west"]. Concatenate them into directions and print the result.
Show one answer
first = ["north", "south"]
second = ["east", "west"]
directions = first + second
print(directions)
['north', 'south', 'east', 'west']
Exercise 2 · Repeat a two-step beat
Create beat = ["clap", "rest"]. Repeat it three times, print the repeated list, then print its length.
Show one answer
beat = ["clap", "rest"]
pattern = beat * 3
print(pattern)
print(len(pattern))
['clap', 'rest', 'clap', 'rest', 'clap', 'rest']
6
Exercise 3 · Combine, then repeat
Create base = ["intro", "lesson"] and footer = ["review"]. Combine them into page, repeat that result twice into copies, and print both lists.
Show one answer
base = ["intro", "lesson"]
footer = ["review"]
page = base + footer
copies = page * 2
print(page)
print(copies)
['intro', 'lesson', 'review']
['intro', 'lesson', 'review', 'intro', 'lesson', 'review']
What you should carry into Lesson 7
You now know two operators that work on entire list sequences. + concatenates compatible lists in order and returns a new list. * repeats a list an integer number of times. Neither operator performs arithmetic on the individual list elements, and neither accepts arbitrary operand types.
The next lesson moves from constructing larger sequences to selecting parts of an existing one. Continue to Slicing Lists and Testing Membership to learn how Python extracts ranges of positions and checks whether a value appears in a collection.
