These are the string methods which both 8-bit strings and Unicode objects support:
) |
For 8-bit strings, this method is locale-dependent.
width[, fillchar]) |
sub[, start[, end]]) |
[start:end]
. Optional arguments start and
end are interpreted as in slice notation.
[encoding[, errors]]) |
'strict'
, meaning that encoding errors raise
UnicodeError. Other possible values are 'ignore'
,
'replace'
and any other name registered via
codecs.register_error.
New in version 2.2.
Changed in version 2.3:
Support for other error handling schemes added.
[encoding[,errors]]) |
'strict'
, meaning that encoding errors raise a
UnicodeError. Other possible values are 'ignore'
,
'replace'
, 'xmlcharrefreplace'
, 'backslashreplace'
and any other name registered via codecs.register_error.
For a list of possible encodings, see section 4.9.2.
New in version 2.0.
Changed in version 2.3:
Support for 'xmlcharrefreplace'
and
'backslashreplace'
and other error handling schemes added.
suffix[, start[, end]]) |
True
if the string ends with the specified suffix,
otherwise return False
. With optional start, test beginning at
that position. With optional end, stop comparing at that position.
[tabsize]) |
8
characters is assumed.
sub[, start[, end]]) |
-1
if sub is
not found.
sub[, start[, end]]) |
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
seq) |
width[, fillchar]) |
len(s)
.
Changed in version 2.4:
Support for the fillchar argument.
) |
For 8-bit strings, this method is locale-dependent.
[chars]) |
None
, the chars argument
defaults to removing whitespace. The chars argument is not
a prefix; rather, all combinations of its values are stripped:
>>> ' spacious '.lstrip() 'spacious ' >>> 'www.example.com'.lstrip('cmowz.') 'example.com'
old, new[, count]) |
sub [,start [,end]]) |
-1
on failure.
sub[, start[, end]]) |
width[, fillchar]) |
len(s)
.
Changed in version 2.4:
Support for the fillchar argument.
[sep [,maxsplit]]) |
None
, any whitespace string is a separator. Except for splitting
from the right, rsplit() behaves like split() which
is described in detail below.
New in version 2.4.
[chars]) |
None
, the chars argument
defaults to removing whitespace. The chars argument is not
a suffix; rather, all combinations of its values are stripped:
>>> ' spacious '.rstrip() ' spacious' >>> 'mississippi'.rstrip('ipz') 'mississ'
[sep [,maxsplit]]) |
maxsplit+1
elements). If maxsplit is not specified, then there
is no limit on the number of splits (all possible splits are made).
Consecutive delimiters are not grouped together and are
deemed to delimit empty strings (for example, "'1,,2'.split(',')"returns "['1', '', '2']"). The sep argument may consist of
multiple characters (for example, "'1, 2, 3'.split(', ')" returns
"['1', '2', '3']"). Splitting an empty string with a specified
separator returns "['']".
If sep is not specified or is None
, a different splitting
algorithm is applied. First, whitespace characters (spaces, tabs,
newlines, returns, and formfeeds) are stripped from both ends. Then,
words are separated by arbitrary length strings of whitespace
characters. Consecutive whitespace delimiters are treated as a single
delimiter ("'1 2 3'.split()" returns "['1', '2', '3']").
Splitting an empty string or a string consisting of just whitespace
returns an empty list.
[keepends]) |
prefix[, start[, end]]) |
True
if string starts with the prefix, otherwise
return False
. With optional start, test string beginning at
that position. With optional end, stop comparing string at that
position.
[chars]) |
None
, the chars
argument defaults to removing whitespace. The chars argument is not
a prefix or suffix; rather, all combinations of its values are stripped:
>>> ' spacious '.strip() 'spacious' >>> 'www.example.com'.strip('cmowz.') 'example'
) |
For 8-bit strings, this method is locale-dependent.
) |
For 8-bit strings, this method is locale-dependent.
table[, deletechars]) |
For Unicode objects, the translate() method does not
accept the optional deletechars argument. Instead, it
returns a copy of the s where all characters have been mapped
through the given translation table which must be a mapping of
Unicode ordinals to Unicode ordinals, Unicode strings or None
.
Unmapped characters are left untouched. Characters mapped to None
are deleted. Note, a more flexible approach is to create a custom
character mapping codec using the codecs module (see
encodings.cp1251 for an example).
) |
For 8-bit strings, this method is locale-dependent.
width) |
len(s)
.
New in version 2.2.2.
See About this document... for information on suggesting changes.