RisingCoder Full course โ†’
Day 1Day 2Day 3Day 4
๐Ÿ“ฆ
STUDENT NOTES ยท DAY 7 OF 24

A Train of Boxes ๐Ÿ“ฆ๐Ÿ“ฆ๐Ÿ“ฆ

One box holds one thing. A LIST is a whole train of boxes under one name โ€” and every wagon has a number.

1Meet the list

๐Ÿ
Py: 60 students = 60 variables? No way. ONE list holds them all. The wagons are numbered starting from 0 โ€” that surprises everyone once!
๐Ÿฆ‰
Professor Hoot: marks[0] is the FIRST wagon. And marks[-1] counts from the back โ€” the last one. Very handy.

2Lists grow and shrink

List builder โ€” add your own wagons!

snacks = []

3Loop + list = power couple

๐Ÿค–
Bittu: sum, max, min, len โ€” I compute these for a million students before you blink.

4Changing a wagon โ€” and Bugly's trap

๐Ÿž
Bugly: Heheheโ€ฆ there are only wagons 0, 1, 2. Ask for wagon 3 andโ€”
๐Ÿ
Py: IndexError = you asked for a wagon that doesn't exist. Check len() when unsure.

5Quick quiz! ๐Ÿง 

fruits = ["mango", "apple", "banana"]. What is fruits[1]?
๐Ÿ’ก Counting starts at 0: mango is [0], apple is [1].
What does fruits[-1] give?
๐Ÿ’ก -1 counts from the back: the LAST item. banana wins.

6Your mission ๐Ÿš€

Mission 1: Make a list of your 4 favourite foods. Print the first and the last using [0] and [-1].
Mission 2: Append a 5th food, then print the new len().
Mission 3: Make a marks list and print the average: sum(marks) / len(marks).

Day 7 done โ€” the train is yours! ๐Ÿš‚

Next: strings โ€” slicing words, shouting in CAPITALS, and secret reversing.

Go to Day 8: Strings โ†’

๐ŸŽฎ Or test yourself in the Python Arcade โ†’