
Specific Built-in Types
|
17
The following sections go into more detail on some of the
methods listed in Table 9. In all of the following that return a
string result, the result is a new string. (Because strings are
immutable, they are never modified in-place.) Whitespace
means spaces, tabs, and end-of-line characters (everything in
string.whitespace).
Searching
s.find(sub, [, start [, end]])
Returns offset of the first occurrence of string sub in s,
between offsets
start and end (which default to 0 and
len(s), the entire string). Returns -1 if not found.
s.rfind(sub, [, start [, end]])
Like find, but scans from the end (right to left).
S.lower()
S.lstrip([chars])
S.replace(old, new [, maxsplit])
S.rfind(sub [,start [,end]])
S.rindex(sub [, start [, end]])
S.rjust(width [, fillchar])
S.rsplit([sep [, maxsplit]])
S.rstrip([chars])
S.split([sep [,maxsplit]])
S.splitlines([keepends])
S.startswith(prefix [, start [, end]])
S.strip([chars])
S.swapcase()
S.title()
S.translate(table [, deletechars])
S.upper()
S.zfill(width)
Table 9. String method calls (continued)