All courses › Programming with Python › Lists
Lists
A list [1, 2, 3] is an ordered, mutable collection of values. You can add to it with append, get its length with len, and slice it just like strings. A tuple (1, 2) is similar but cannot be changed after it is created.
number of elements in the list
adds to the end
Symbols
| a list | ||
| the value being added |
Example
x = [1, 2, 3]
x.append(4) makes x [1, 2, 3, 4], and len(x) becomes 4.
Lists are passed to functions by reference: if the function changes the list, you see the change outside too.
Practise python basics for free →