Skip to main content
  1. Notes/
  2. Python 🐍/

πŸ“‹ Lists in Python | Lesson 05

Python Progmramming Course
Table of Contents
Python - This article is part of a series.
Part 5: This Article

πŸ“‹ Lists in Python
#

Lists are one of the most useful and flexible data structures in Python. They let you store collections of itemsβ€”whether numbers, strings, or even other lists! Get ready to learn how to create, modify, and use lists like a pro. πŸ”₯


What is a List? 🧩
#

A list is an ordered collection of items enclosed in square brackets [ ]. You can store multiple values in one list.

fruits = ["apple", "banana", "cherry"]
numbers = [10, 20, 30, 40]

Creating Lists ✍️
#

Lists can contain any type of data and even a mix of types!

mixed_list = [1, "hello", True, 3.14]
empty_list = []

Accessing Items in a List πŸ”Ž
#

Use indexing to access elements (starting at 0).

print(fruits[^0])    # apple
print(fruits[-1])   # cherry (last item)

Modifying Lists ✏️
#

You can change values, add new items, or remove items.

# Change item
fruits[^1] = "blueberry"

# Add item (append adds to the end)
fruits.append("orange")

# Insert item at specific position
fruits.insert(1, "mango")

# Remove item by value
fruits.remove("apple")

# Remove item by position
del fruits[^2]

List Operations πŸ”’
#

OperationExampleResult
Concatenate[^1][^2] +[^1][^2]
Repeat* 3``
Lengthlen(fruits)Number of items in list
Check membership"apple" in fruitsTrue or False

Looping Through Lists πŸ”„
#

You can use a for loop to go through each item.

for fruit in fruits:
    print(fruit)

Practice Questions with Solutions πŸ†
#

  1. Practice: Create a list of your 3 favorite colors and print the first color.
    • Solution:
colors = ["red", "green", "blue"]
print(colors)
  1. Practice: Add the color “yellow” at the end of the list.
    • Solution:
colors.append("yellow")
  1. Practice: Remove the second item from the list.
    • Solution:
del colors[^1]

Step-by-Step Mini Project: Shopping List πŸ›’
#

Create a shopping list program that:

  • Starts with empty list
  • Adds 3 items to the list
  • Prints all items to the user

Solution:

shopping_list = []
shopping_list.append("milk")
shopping_list.append("bread")
shopping_list.append("eggs")

print("Your shopping list:")
for item in shopping_list:
    print("-", item)

Checklist for This Chapter βœ…
#

  • Created and accessed lists
  • Modified, added, and removed list items
  • Used list operations (concatenation, repetition)
  • Loop through lists for display

You’re mastering Python lists! Start collecting and organizing data with ease. Keep practicing by making playlists, scores, or task lists! πŸŽ‰

⁂
Aryan
Author
Aryan
A little bit about you
Python - This article is part of a series.
Part 5: This Article

Related

⏰ Working with Date and Time in Python | Lesson 16
Python Progmramming Course
🎬 Strings in Python | Lesson 04
Python Progmramming Course
πŸ—οΈ Object-Oriented Programming (OOP) Concepts in Python | Lesson 15
Python Progmramming Course
πŸ‘Ά Python Basics | Lesson 02
Python Progmramming Course
πŸ“„ File Handling in Python | Lesson 14
Python Progmramming Course
πŸ“– Dictionaries in Python | Lesson 07
Python Progmramming Course