+91 81900 98289

Join Lists

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.

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)

Add two lists

Plus joins lists into a new list.

print(["Python"] + ["SQL", "Git"]) # print writes this; the quotes are not shown

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)

Repeat a list

Multiplying a list repeats its items.

print([0] * 3) # print writes this; the quotes are not shown
After extend, core itself holds all three names.