TalentJR

Lesson 10

Introduction to Lists

Store and loop through collections

1What is a List?✨

A list in Python is a collection of items stored in a single variable. Lists can hold different types of data, making them very flexible and useful for organizing information!

2Why Use Lists?🎯

  • ✓ Store multiple items in one variable
  • ✓ Easily loop through items
  • ✓ Modify, add, or remove items
  • ✓ Ideal for managing data like names, scores, and more

3Creating a List💡

You create a list by placing items inside square brackets, separated by commas. Here’s how you can create a list of fruits:

💻 code
fruits = ["apple", "banana", "cherry"]
print(fruits)

This code will display the entire list of fruits.

4Accessing List Items🚀

You can access items in a list using their index, which starts at 0. Here’s how to get the first fruit in the list:

💻 code
print(fruits[0])

This will output "apple" since it is the first item in the list.

5Looping Through a List🔍

You can use a for loop to go through each item in a list. Here’s an example that prints each fruit:

💻 code
for fruit in fruits:
    print(fruit)

This loop will display each fruit on a new line.

6Modifying a List⭐

💻 code
Lists are mutable, meaning you can change them! You can add items with the append() method. Let’s add a new fruit:
💻 code
fruits.append("orange")
print(fruits)

Now the list will include "orange" at the end!

🎯 Practice Challenges

Master Introduction to Lists by completing all 3 difficulty levels

🟢 EASY

Introduction to Lists - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Introduction to Lists - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Introduction to Lists - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Introduction to Lists? 🚀

Complete the challenges, take the quiz and keep your learning streak going!