Outline for February 6, 2012

Reading: §8

  1. Sequences
    1. Accustomed to use in for loops (for i in range(5):)
    2. Sequences are a series of values in a particular order
    3. In Python predominantly strings and lists but also sets and tuples
  2. Strings
    1. Sequence of characters (characters are strings of length 1)
    2. Strings are immutable; really important for functions
  3. Basic string operations
    1. +, concatenation for strings
    2. *, repetition repeats given value
    3. len() returns length of sequence
  4. Indexing, var[position]
    1. Count from 0 to len(var)−1
    2. Position can be a negative number to count from right
  5. Assignment with indexing doesn’t work as strings immutable
  6. Slicing, var[start:end]
    1. Value at index end not included in slice
    2. If omitted, starting value defaults to 0 and ending value defaults to last index + 1
    3. Can use negative index
  7. String module import string
    1. String methods: s.capitalize(), s.replace(old, new), s.find(sub), s.rfind(sub), s.upper(), s.lower()

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