๐ฆ
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 โ