Python Learning Series · @onlysamarrr · Day 12 / 30
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
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.
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:])
10 30 3 - milk - bread - eggs ['bread', 'eggs']
Shopping carts, playlists and to-do lists are all lists in real programs.
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?
| 56/450 | Concept | List kya hai |
| 57/450 | Live demo | Indexing aur negative index |
| 58/450 | Common mistake | IndexError kyun aata |
| 59/450 | Quiz | Quiz: list ka last item |
| 60/450 | Interview / real life | Real life: shopping list |