Python Learning Series · @onlysamarrr · Day 12 / 30

Day 12: Lists Basics

Day 12 teaches lists. A list holds many values in one place. Indexing starts at 0, and negative indexing counts from the end: -1 is the last item.

Phase: Beginner · Reels: 56/450 – 60/450

Quick Answer

Day 12 teaches lists. A list holds many values in one place. Indexing starts at 0, and negative indexing counts from the end: -1 is the last item.

What You Will Learn

Code

nums = [10, 20, 30]
print(nums[0], nums[-1])
print(len(nums))
shopping = ["milk", "bread", "eggs"]
for item in shopping:
    print("-", item)
print(shopping[1:])

Output

10 30
3
- milk
- bread
- eggs
['bread', 'eggs']

Code Explained, Line by Line

  1. nums = [10, 20, 30] creates a list inside square brackets.
  2. nums[0] is 10 (first) and nums[-1] is 30 (last). Negative indexes count backwards.
  3. len(nums) is 3: it counts how many items are in the list.
  4. for item in shopping runs once for every item in the list.
  5. shopping[1:] is slicing: it returns items from index 1 to the end.
Common Mistake: Asking for an index outside the list raises IndexError. A 3-item list has indexes 0, 1 and 2, so nums[3] is invalid.

Real-Life Use

Shopping carts, playlists and to-do lists are all lists in real programs.

Practice Task: Make your own shopping list and print its last item using a negative index.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. In nums = [10, 20, 30], what is nums[-1]?

Q2. What is len([10, 20, 30])?

Q3. What does nums[3] give for a 3-item list?

Today's 5 Reels (from the 90-Day Plan Excel)

56/450ConceptList kya hai
57/450Live demoIndexing aur negative index
58/450Common mistakeIndexError kyun aata
59/450QuizQuiz: list ka last item
60/450Interview / real lifeReal life: shopping list
← Day 11Day 13 →