Lists and ordered data.
Use positions, slices, and iteration while keeping mutation visible.
Start here.
A list is an ordered, changeable collection. Square brackets create it, and commas separate its elements: names = ['Ada', 'Grace', 'Linus']. A position is called an index. Python starts indexing at zero, so names[0] is 'Ada', names[1] is 'Grace', and names[2] is 'Linus'. A negative index counts backward; names[-1] is the final element. Reading an index outside the list raises IndexError instead of inventing a value.
A slice selects a range: names[1:3] begins at index 1 and stops before index 3. The omitted end in names[1:] means continue to the end. A slice makes a new list, while names.append('Maya') changes the original list. Because lists are mutable, two names can refer to one list. If second = names, then second.append(...) changes what names also sees. A slice copies the outer list but still shares any mutable objects stored inside it.
Iteration usually reads more clearly than manual indexing. for name in names gives each value directly. enumerate(names) gives an index and value when both matter. A list comprehension is a compact expression that creates a new list, such as [name.upper() for name in names]. It reads as 'make the uppercase version of each name'. Start with a simple loop when the transformation has several decisions; compact syntax should still reveal the rule.
Build the model.
A list keeps values in order and gives each a zero-based index. It is useful when position matters or when you need to walk through items in the order you received them. list[0] reads the first item; list[-1] reads the last. A slice such as list[1:3] creates a new list from index 1 up to, but not including, index 3.
Lists are mutable, so append, remove, or assignment can change the same list object that another name also refers to. This is convenient when one owner is building a collection, but it can surprise a caller that expected its input to stay unchanged. Decide whether a function changes a supplied list or returns a new one, and make that choice visible in its name or documentation.
How it works.
The index is about position, not a permanent identity. If you insert an item near the front, later indexes shift. Use for item in items when you only need values; use enumerate(items) when you need both index and value. A comprehension expresses a small transformation or filter in one expression and returns a new list, but several nested clauses often read better as a loop.
A tuple is an ordered, immutable sequence. It suits a fixed set of related values such as a coordinate or a function returning two results. Unpacking assigns those positions to names. The tuple's immutability does not freeze mutable objects stored inside it, so still think about shared references when nested data can change.
Read it line by line.
names = ['Ada', 'Grace', 'Linus']
first = names[0]
remaining = names[1:]
print(first, remaining)Index 0 selects 'Ada'. The slice starts at index 1 and has no explicit end, so it copies 'Grace' and 'Linus' into a new list. print shows Ada followed by ['Grace', 'Linus']. Changing remaining later will not insert or remove items from names, although nested objects would still be shared.
See the rule again.
names = ['Ada', 'Grace']
upper = [name.upper() for name in names]
print(upper)
print(names)The outputs are ['ADA', 'GRACE'] and ['Ada', 'Grace']. The comprehension calls upper on each string and collects results in a new list. Strings are immutable, so the original values remain as they were.
A mistake to avoid.
A slice and list.copy() are shallow. If the elements are dictionaries, both lists still point to those same dictionaries. Copy deeper layers when previous state must remain unchanged.