Outline for October 29, 2020

Reading: §8
Due: Homework 2, due October 30, 2020


  1. I have to change my office hours tomorrow. I am moving them to 3:30pm–4:30pm.

  2. Lists
    1. Sequence of values (ints, floats, strings, other lists, etc.)
    2. Denoted by square brackets [ ] with values separated by commas
    3. Lists are mutable
    4. How to create a list

  3. Lists and strings [datecvt.py]

  4. Program to print words in a line [lines.py]

  5. What you can do with lists
    1. Check membership: in, not in
    2. +: concatenation
    3. *: repetition
    4. list[a:b]: slice list from a to b-1
    5. del list[i]: delete element list[i]; i can be a slice

  6. 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)

  7. Objects, references, aliasing
    1. For strings, one copy: assume a = "banana"
      1. After b = a or b = a[:], then a is b is True
    2. For lists, multiple copies: assume A = [ 1, 2, 3 ]
      1. After B = A then A is B is True
      2. After B = A[:], then A is B is False


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
MHI 289I, Programming for Health Informatics
Version of October 28, 2020 at 11:20PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh