This Join Lists lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
The + operator builds a new list from two lists. extend adds every item of the second list onto the first.
+ does not change either original. extend changes the list you call it on.
Example 1: Start here
After extend, core itself holds all three names.
core = ["Python"] # a list; the values stay in this order
extra = ["SQL", "Git"] # a list; the values stay in this order
print(core + extra)
core.extend(extra)
print(core)
Example 2: Add two lists
Plus joins lists into a new list.
print(["Python"] + ["SQL", "Git"]) # print writes this; the quotes are not shown
Example 3: Extend in place
extend adds every item from the second list.
skills = ["Python"] # a list; the values stay in this order
skills.extend(["SQL", "Git"])
print(skills)
Example 4: Repeat a list
Multiplying a list repeats its items.
print([0] * 3) # print writes this; the quotes are not shown
