Python Lists: Fixed-Length, Growable & Index Operations
A `List<T>` (array equivalent) is an ordered collection of elements. Lists in Dart can be growable (default `[...]` literals that expand dynamically with `.add()`) or fixed-length (`List.filled(5, 0, growable: false)` for cache-efficient pre-allocated memory buffers). Lists are 0-indexed and provide methods like `.contains()`, `.indexOf()`, `.sublist()`, and `.sort()`.
"A growable list is like a loose-leaf binder where you can insert new pages anytime; a fixed-length list is a hardbound notebook with exactly 100 numbered pages."
Deep Dive: How It Works
Growable vs Fixed: Growable lists dynamically resize memory arrays; fixed-length lists disallow `.add()` or `.remove()`.
Index Access: `list[0]` for read, `list[1] = value` for write.
Immutable Lists: `List.unmodifiable([1, 2, 3])` prevents all subsequent mutations at runtime.
Syntax Blueprint
var fruits = ["Apple", "Banana"]; // Growable List<String>
fruits.add("Cherry");
fruits.remove("Banana");
print(fruits[0]); // "Apple"Growable list declaration, mutation, and index access.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Accessing `list[list.length]` and encountering `RangeError (index)`.Why it happens: Lists are 0-indexed; the final element is at index `list.length - 1` (or use `list.last`).
How to fix: Use `list.first` and `list.last` for safe boundary element access.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Initialize and Sift List
Create a growable list `final list = [3, 1, 4];`.
Add `2` using `.add(2)`, sort the list with `.sort()`.
Print `List: $list`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.