- The Python Docs Tutorial for strings has an overview of the Python
str
type. - String methods .join() and .split() ar very helpful when processing strings.
- The Python Docs on Sequence Types has a rundown of operations common to all sequences, including
strings
,lists
,tuples
, andranges
.
There's four activities in the assignment, each with a set of text or words to work with.
- Small strings can be concatenated with the
+
operator.
- Believe it or not,
<str>.join()
is all you need. - Like
<str>.split()
,<str>.join()
can take an arbitrary-length string, made up of any unicode code points.
- Strings can be both indexed and sliced from either the left (starting at 0) or the right (starting at -1).
- If you want the last code point of an arbitrary-length string, you can use [-1].
- The last three letters in a string can be "sliced off" using a negative index. e.g. 'beautiful'[:-3] == 'beauti'
- Using
<str>.split()
returns a list of strings broken on white space. lists
are sequences, and can be indexed.<str>.split()
can be direcly indexed. e.g.'Exercism rocks!'.split()[0] == 'Exercism'
- Be careful of punctuation! Periods can be removed via slice:
'dark.'[:-1] == 'dark'