This Python Lists lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.
A list keeps values in order and lets you change them. Square brackets create one. Indexes start at 0.
append adds at the end. pop removes by index. A negative index counts from the end.
Example 1: Start here
Assigning one list to two names shares the same list. Use copy when you need a separate one.
skills = ["Python", "SQL"] # a list; the values stay in this order
skills.append("Git") # add one item at the end of the list
print(skills[0])
print(skills[-1])
Example 2: Read by position
The first item is index 0. A negative index starts from the end.
skills = ["Python", "SQL", "Git"] # a list; the values stay in this order
print(skills[0])
print(skills[-1])
Example 3: Change one item
You can replace the item at an index.
scores = [70, 80, 90] # a list; the values stay in this order
scores[1] = 85 # change this one field
print(scores)
Example 4: Add an item
append adds one item at the end.
skills = ["Python"] # a list; the values stay in this order
skills.append("SQL") # add one item at the end of the list
print(skills)
