Skip to content

list

List literals [1, 2, 3], list(iterable), and methods returning lists.

MethodReturnsMeaning
.lengthnumberItem count, same as len(lst). Property: no parens
.append(item)NoneAdd to the end (raises past the interpreter’s max-length cap)
.pop(index=-1)anyRemove and return (default last); negative indices from the end; empty/out-of-range raises
.remove(item)NoneRemove first occurrence by value; raises if absent
.insert(index, item)NoneInsert, shifting right; out-of-range indices clamp to the ends (no error)
.index(item, start=0, end=None)numberFirst occurrence in the slice; raises if not found
.count(item)numberOccurrences (deep value equality for numbers, strings, booleans)
.sort(key=None, reverse=False)NoneIn-place sort using <. key= must be pure: it cannot suspend the script or mutate game state
.reverse()NoneReverse in place
.copy()listShallow copy
.extend(iterable)NoneAppend every item from a finite iterable
.clear()NoneRemove all items