Outline for November 14, 2012
Reading: § 14
Assignment Due: Wednesday, November 28, 2012 at 5:00 PM
- Lists
- Sequence of values (ints, floats, strings, other lists, etc.)
- Denoted by square brackets [ ] with values separated by commas
- Lists are mutable
- How to create a list
- Type conversion
- str(val) attempts to convert val to a string
- list(sequence) attempts to convert sequence to a list
- Program to print words in a line [lines.py]
- Program to compute some statistics [addup.py]
- What you can do with lists
- Check membership: in, not in
- +: concatenation
- *: repetition
- list[a:b]: slice list from a to b−1
- del list[item]: delete list[item]; item can be a slice
- Objects, references, aliasing
- For strings, one copy: assume a = "banana"
- After b = a or b = a[:], then a is b is True
- For lists, multiple copies: assume A = [ 1, 2, 3 ]
- After B = A, then A is B is True
- After B = A[:], then A is B is False
- Lists as parameters: can change list elements in function and they are changed in caller [args2.py]
A PDF version is available here.
|
ECS 10, Basic Concepts of Computing
Fall Quarter 2012
|