Outline for May 6, 2014
Reading
:
text
, § 8
Due
: Homework #2, due May 9, 2014 (
Note extension
)
Sequences
Sequences are a series of values in a particular order
In Python predominantly strings and lists but also sets and tuples
Strings
Sequence of characters (characters are strings of length 1)
Strings are immutable; really important for functions
Basic string operations
+
, concatenation for strings
*
, repetition repeats given value
len()
returns length of sequence
s in str
returns
True
if
s
is a substring of
str
,
False
otherwise
Indexing,
var[position]
Count from 0 to
len(var)−1
Position can be a negative number to count from right
Assignment with indexing doesn’t work as strings immutable
x = 'hEllo'; x[1] = 'e'
produces an error
Slicing,
var[start:end]
Value at index end not included in slice
If omitted, starting value defaults to 0 and ending value defaults to last index + 1
Can use negative index
Example program [
strstuff.py
]
You can also obtain a PDF version of this.
Version of May 5, 2014 at 7:46PM