👋 Work With Me

I help startups and teams build production-ready apps with Django, Flask, and FastAPI.

Let’s Talk →

I'm always excited to take on new projects and collaborate with innovative minds.

Address

No 7 Street E, Federal Low-cost Housing Estate, Kuje, Abuja 903101, Federal Capital Territory

Social Links

Tutorials

Python Tutorial Series – Lesson 5: Lists in Python

Python Tutorial for Beginners (Lesson 5): Learn lists in Python with examples, screenshots, and exercises – list creation, indexing, slicing, and methods explained.

Python Tutorial Series – Lesson 5: Lists in Python

Welcome back to the Python Tutorial Series for Beginners! 🎉

In Lesson 4, we explored strings – how to create them, manipulate them, and use powerful built-in methods.

Now in Lesson 5, we’re diving into lists – one of the most useful and versatile data structures in Python.

By the end of this lesson, you’ll understand:

  • What lists are and how to create them
  • Accessing, slicing, and modifying lists
  • Common list methods
  • Nesting lists (lists inside lists)
  • Practical exercises to solidify your knowledge

🔹 What is a List?

A list is a collection of items (elements) stored in a specific order. You can store numbers, strings, or even other lists inside a list.

 
# Examples of lists

fruits = ["apple", "banana", "cherry"]
numbers = [10, 20, 30, 40]
mixed = ["Python", 3.14, True, 42]
  • Lists are written with square brackets []
  • They can contain different data types

 


🔹 1. Accessing List Elements

Just like strings, lists are indexed (starting at 0).

 
fruits = ["apple", "banana", "cherry"]

print(fruits[0])   # First item → apple
print(fruits[-1])  # Last item → cherry

🔹 2. Modifying Lists

Lists are mutable (you can change them after creation).

 
fruits = ["apple", "banana", "cherry"]

fruits[1] = "orange"
print(fruits)   # ['apple', 'orange', 'cherry']

🔹 3. Slicing Lists

You can extract parts of a list using slicing.

 
numbers = [10, 20, 30, 40, 50]

print(numbers[1:4])   # [20, 30, 40]
print(numbers[:3])    # [10, 20, 30]
print(numbers[2:])    # [30, 40, 50]

🔹 4. Common List Methods

Python provides many built-in methods for working with lists.

 
fruits = ["apple", "banana", "cherry"]

fruits.append("mango")     # Add item at end
fruits.insert(1, "orange") # Insert at index 1
fruits.remove("banana")    # Remove specific item
fruits.pop()               # Remove last item
fruits.sort()              # Sort list alphabetically
fruits.reverse()           # Reverse the list

print(fruits)

🔹 5. Nesting Lists (Lists Inside Lists)

You can store lists inside other lists (like a 2D table).

 
matrix = [
   [1, 2, 3],
   [4, 5, 6],
   [7, 8, 9]
]

print(matrix[0][1])   # Access second element of first list → 2

🔹 Exercises for Beginners

Try these in a new file (lesson5.py):

  1. Create a list of your 5 favorite foods and print the first and last item.
  2. Modify the second item in the list to something new.
  3. Use slicing to print only the middle 3 numbers from [1,2,3,4,5,6,7].
  4. Create a list of 3 names, then:
    • Add another name using .append()
    • Remove one name using .remove()
  5. Challenge: Create a 2D list (matrix) and print the element in row 2, column 3.

🎯 Recap

In this lesson, you learned:
✅ Lists are collections of items in square brackets
✅ You can access, modify, and slice list elements
✅ Lists have powerful built-in methods
✅ You can even nest lists for multi-dimensional data

Next up: Lesson 6 – Tuples in Python (an introduction to immutable sequences). 📚

💼 Need a Developer?

I'm Kingsley Odume, a Django, Flask, and FastAPI developer with experience building SaaS platforms, APIs, and modern web apps. If you're a recruiter or business owner looking for a reliable software developer, let's connect!

🚀 Hire Me

Python, Python tutorials, Python Beginners series, Python Step-byStep
3 min read
Aug 20, 2025
By Kingsley Odume
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Aug 29, 2025 • 3 min read
Step-by-Step: Building a SaaS App with Django + Stripe Payments

Learn how to build a real-world SaaS app with Django and Stripe paymen...

Aug 21, 2025 • 3 min read
Final Wrap-Up: Python Tutorial Series for Beginners

Congratulations on completing the Python Tutorial Series! 🚀 In this w...

Aug 20, 2025 • 4 min read
Final Lesson: Mini Project – Putting It All Together in Python

In this final lesson, we’ll bring all those concepts together in a Min...

Your experience on this site will be improved by allowing cookies. Cookie Policy