List in python: quick revision, 14 bites
All 14 revision bites from this kit, free and with no sign-up.
What is a Python List?
The Swiss Army knife of data.
A **list** in Python is an ordered, mutable collection of items. It can hold elements of different types (integers, strings, even other lists) and is defined using square brackets `[]`. Lists are zero-indexed, meaning the first element is at index `0`.
Takeaway. A Python list is an ordered, changeable sequence written as a comma-separated list inside square brackets.
List Creation
Start with empty or filled.
Create a list by placing items inside `[]` separated by commas. An empty list is simply `[]` or using the `list()` constructor.
Takeaway. Use square brackets or the list() constructor to create a list.
Indexing and Negative Indexing
Start at 0, end at -1.
Access items by their position. The first item has index `0`, the second `1`, and so on. Python also supports **negative indexing**, where `-1` refers to the last item, `-2` to the second last, etc.
Takeaway. Use positive indices from the start (0) and negative indices from the end (-1).
Slicing a List
Get a sublist quickly.
Use the slice syntax `[start:stop:step]` to extract a portion of the list. `start` is inclusive, `stop` is exclusive, and `step` is optional (default 1).
Takeaway. Slicing returns a new list from the original using start:stop:step.
Index Out of Range
Don't go beyond the end.
Takeaway. Check list length before accessing an index to avoid IndexError.
Modifying List Items
Lists are mutable—change them.
Since lists are mutable, you can change an item by assigning a new value to its index. You can also replace a slice with a new list.
Takeaway. Assign to an index or slice to modify list contents in place.
Adding Items: append vs extend
One adds, one merges.
`append()` adds a single item to the end of the list. `extend()` adds all elements of an iterable (like another list) to the end.
Takeaway. Use append() for one item, extend() to merge another list's items.
Removing Items: remove, pop, del
Three ways to delete.
`remove(x)` deletes the first occurrence of value `x`. `pop(i)` removes and returns the item at index `i` (default last). `del list[i]` deletes by index without returning.
Takeaway. remove() by value, pop() by index (returns item), del by index.
List Length with len()
Count your items fast.
The built-in `len()` function returns the number of items in a list. It's O(1) — constant time — because Python stores the length internally.
Takeaway. Use len(list) to get the number of elements quickly.
List vs Tuple
Mutable vs immutable.
Takeaway. Lists are mutable and slower; tuples are immutable and faster.
List Comprehensions
Build lists in one line.
A **list comprehension** provides a concise way to create lists. Syntax: `[expression for item in iterable if condition]`. It's often faster and more readable than a for loop.
Takeaway. Use list comprehensions for clean, efficient list creation.
Remember Index Start at 0
Zero is the first hero.
Think of a ruler: the first inch starts at 0, not 1. Similarly, Python lists start at index 0. Mnemonic: **Z**ero-based **I**ndexing = **ZI**.
Takeaway. Always remember: first element = index 0.
Common Exam: Reverse a List
Three ways to reverse.
To reverse a list, you can use: `list.reverse()` (in-place), slicing `[::-1]` (returns new list), or `reversed(list)` (returns iterator). Slicing is often tested.
Takeaway. Use [::-1] to quickly reverse a list in exams.
Lists Can Hold Mixed Types
Not just numbers!
Unlike arrays in many languages, Python lists can hold items of different data types in the same list, including other lists (nested lists).
Takeaway. Lists are heterogeneous—they can store any data type.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages