changeset 522 | d33698326409 |
child 523 | 54bdda4aefa5 |
521:88a01948450d | 522:d33698326409 |
---|---|
1 \textbf{Manipulating strings} |
|
2 |
|
3 String indexing starts from 0, like lists. |
|
4 |
|
5 \lstinline|s = `Hello World'|\\ |
|
6 \lstinline|s[0:5]| gives \texttt{Hello}\\ |
|
7 \lstinline|s[6:]| gives \textt{World}\\ |
|
8 \lstinline|s[6::2]| gives \textt{Wrd}\\ |
|
9 |
|
10 \lstinline|s.replace('e', 'a')| returns a new string with all e's |
|
11 replaced by a. |
|
12 |
|
13 \lstinline|s.lower()| and \lstinline|s.upper()| return new strings |
|
14 with all lower and upper case letters, respectively. |