Lists and Tuples

Lesson 7 of 20

Grow lists with append, slice them any way you like — and meet tuples, the ordered collections that never change.

The big picture

Ordered collections

Lists keep items in order and change freely; tuples are their frozen cousins — same order, no edits.

Lists Grow

append(x) adds to the end, and len(nums) always knows the size.

Zero-Based Index

The first element is nums[0]; the last is nums[len(nums) - 1].

End-Exclusive Slices

nums[1:3] takes indexes 1 and 2 — the end index is never included.

Tuples Freeze

(3, 1, 4) is a tuple: indexable and sliceable, but no append and no edits — ever.