blob: 71b721f66e9cd39e74748bc3fb439bb5fb8b0358 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
\textbf{Manipulating strings}
String indexing starts from 0, like lists.
\lstinline|s = `Hello World'|\\
\lstinline|s[0:5]| gives \texttt{Hello}\\
\lstinline|s[6:]| gives \texttt{World}\\
\lstinline|s[6::2]| gives \texttt{Wrd}\\
\lstinline|s.replace('e', 'a')| returns a new string with all e's
replaced by a.
\lstinline|s.lower()| and \lstinline|s.upper()| return new strings
with all lower and upper case letters, respectively.
|