Python Lists

3 min read ·

Lists are one of the most important and widely used data structures in Python. They allow you to store multiple values in a single variable, and they are ordered, mutable, and flexible.
Lists are used everywhere—from basic programs to real-world applications.

What Is a List?

A list is a collection that:
  • Is ordered
  • Is mutable (can be changed)
  • Allows duplicate values
  • Can store different data types

Creating a List

Using Square Brackets


Using list() Constructor


Access List Items (Indexing)

List items are indexed starting from 0.

Change List Items (Mutable Nature)


List Length


Check Item Exists


Loop Through a List


Add Items to a List

append() – Add at the End


insert() – Add at Specific Index


Remove Items from a List

remove() – Remove by Value


pop() – Remove by Index


del Keyword


List Slicing


Copy a List (Important)

Wrong Way (Reference Copy)


Correct Way (Actual Copy)


Sort a List


Reverse a List


List Methods (Quick Overview)

MethodDescription
append()Add item
insert()Insert at index
remove()Remove value
pop()Remove index
sort()Sort list
reverse()Reverse list
copy()Copy list
clear()Remove all items
count()Count occurrences
index()Find index

List with Mixed Data Types


Common Mistakes

Modifying List While Iterating


Practice

  • Create a list of numbers and modify it
  • Add and remove elements
  • Copy a list safely
  • Sort and reverse a list