Outline for February 10, 2012
Reading:
§11
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
Assign “banana” to variables
a
,
b
For strings, one copy (
a is b
is
True
) [immutable]
For lists, multiple copies (
a is b
is
False
[mutable]
For lists,
a = [ 1, 2, 3 ]; b = a
; then
a is b
is
True
But . . .
a = [ 1, 2, 3 ]; b = a[:]
; then
a is b
is
False
A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012