What is a list?
Section 5: ListsLesson 5.1 · ⏱ 7 min
A list is a variable that keeps many things in order, between square brackets [ ]. Counting starts from zero.
robots = ["Robo", "Bolt", "Nova"]
print(robots[0])
print(len(robots))
robots.append("Zip")
print(robots)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Robo 3 ['Robo', 'Bolt', 'Nova', 'Zip']

📌 Another example: add and remove
append adds at the end, and remove deletes.
pets = ["cat", "dog"]
pets.append("fish")
pets.remove("dog")
print(pets)
print(len(pets))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗['cat', 'fish'] 2
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A list of three colours, and print the first and the last.
👀 Show the solution🙈 Hide the solution
colors = ["red", "green", "blue"]
print(colors[0])
print(colors[-1])
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗red blue
Result: red, then blue
Medium
Sort a list of numbers from the smallest to the biggest.
👀 Show the solution🙈 Hide the solution
nums = [5, 2, 9, 1]
nums.sort()
print(nums)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗[1, 2, 5, 9]
Result: [1, 2, 5, 9]
Hard
The biggest number, the smallest number and the sum of the list.
👀 Show the solution🙈 Hide the solution
nums = [12, 7, 30, 4]
print(max(nums), min(nums), sum(nums))
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗30 4 53
Result: 30 4 53

