Outline for February 13, 2012

Reading: §14

  1. Objects, references, aliasing (Correction from last lecture)
    1. Assign “banana” to variables a, b
    2. For strings, one copy (a is b is True) [immutable]
    3. For strings, a = "hello"; b = a; then a is b is True
    4. Also, a = "hello"; b = a[:]; then a is b is True
    5. For lists, multiple copies (a is b is False [mutable]
    6. For lists, a = [ 1, 2, 3 ]; b = a; then a is b is True
    7. But . . . a = [ 1, 2, 3 ]; b = a[:]; then a is b is False
  2. Lists as parameters: can change list elements in function and they are changed in caller [args2.py]
  3. List methods
    1. Add elements to, remove elements: L.append(x), L.extend(ls), L.insert(i, x), L.pop(), L.remove(x)
    2. Element ordering: L.reverse(), L.sort()
    3. Other: L.count(x), L.index(x)
    4. Example use: linear search [linsearch.py]
  4. Tuples
    1. Used to group data
    2. Like lists, but immutable

A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012