| Line 82: |
Line 82: |
| | === Collections === | | === Collections === |
| | ==== List ==== | | ==== List ==== |
| − | | + | Collection - allows us to put many values in a single variable. |
| | + | Simple variables are not collections. The previous value is overwritten when changed. |
| | + | * A List is made up of list 'constants'. Lists are surrounded by square brackets [] and the constants in the list are separated by commas. ([2,4,6,8]) |
| | + | * A List element can be any Python object, even another list |
| | + | * A List can be empty |
| | + | * Lists are mutable (they can be changed) |
| | + | * When len() is used on a list, it counts the number of constants that make up the list. (not the number of characters) |
| | + | * Lists can be concatenated using + |
| | + | * Lists can be sliced |
| | + | * List is a unique type that can be checked using type() (result: <type 'list'>) |
| | + | * An empty list can be created with list() |
| | + | * Lists can be tested for contents using in/not in |
| | + | * List is an ordered sequence |
| | + | * A list can be sorted with .sort(). Sort changes the list permanently. |
| | * sorted(list) → Returns a list sorted. | | * sorted(list) → Returns a list sorted. |
| | + | * Methods: append, count, extend, index, insert, pop, remove, reverse, sort |
| | + | * Functions len() - find length, max() - find highest value, min() - find lowest value, sum() - add all values average can be found with sum()/len() |
| | | | |
| | ==== Tuple ==== | | ==== Tuple ==== |