Lists
If you're coming from another language
Python’s list is closer to Java’s ArrayList or JavaScript’s Array than
to a C-style fixed array — it resizes automatically and isn’t restricted to
one type:
This flexibility is convenient, but it also means Python won’t catch a type mistake in a list at compile time the way a strictly-typed array would — worth keeping in mind given what we covered about runtime vs. compile-time errors.
Literal syntax and indexing
A list is an ordered, mutable collection — you’ve already seen the syntax used without explanation earlier:
Negative indexing is Python-specific — if you’re coming from Java/C++,
there’s no tools[tools.length - 1] needed; -1 just means “last.”
Slicing
list[start:stop] pulls a sub-list — start is inclusive, stop is
exclusive:
Mutability and common methods
Lists can be changed in place after creation — this is different from
strings, which are immutable in Python (an operation like .upper()
returns a new string rather than modifying the original):
.sort() modifies the list in place and returns None; it doesn’t return
the sorted list. If you want a sorted copy without touching the original,
use sorted(numbers) instead, which returns a new list.
Which existing data structure is Python's list closest to?
Sort the scores in descending order, then slice out the top two.