A collection of string operations (most are no longer used).
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by a
built-in module called strop, but strop is now obsolete itself.
whitespace -- a string containing all characters considered whitespace
lowercase -- a string containing all characters considered lowercase
letters uppercase -- a string containing all characters considered
uppercase letters letters -- a string containing all characters
considered letters digits -- a string containing all characters
considered decimal digits hexdigits -- a string containing all characters
considered hexadecimal digits octdigits -- a string containing all
characters considered octal digits punctuation -- a string containing all
characters considered punctuation printable -- a string containing all
characters considered printable
|
capwords(s,
sep=None)
capwords(s, [sep]) -> string |
|
|
string
|
lower(s)
Return a copy of the string s converted to lowercase. |
|
|
string
|
upper(s)
Return a copy of the string s converted to uppercase. |
|
|
string
|
swapcase(s)
Return a copy of the string s with upper case characters converted to
lowercase and vice versa. |
|
|
string
|
strip(s,
chars=...)
Return a copy of the string s with leading and trailing whitespace
removed. |
|
|
string
|
lstrip(s,
chars=...)
Return a copy of the string s with leading whitespace removed. |
|
|
string
|
rstrip(s,
chars=...)
Return a copy of the string s with trailing whitespace removed. |
|
|
list of strings
|
split(s,
sep=... ,
maxsplit=...)
Return a list of the words in the string s, using sep as the
delimiter string. |
|
|
list of strings
|
splitfields(s,
sep=... ,
maxsplit=...)
Return a list of the words in the string s, using sep as the
delimiter string. |
|
|
list of strings
|
rsplit(s,
sep=... ,
maxsplit=...)
Return a list of the words in the string s, using sep as the
delimiter string, starting at the end of the string and working to
the front. |
|
|
string
|
join(list,
sep=...)
Return a string composed of the words in list, with intervening
occurrences of sep. |
|
|
string
|
joinfields(list,
sep=...)
Return a string composed of the words in list, with intervening
occurrences of sep. |
|
|
int
|
index(s,
sub,
start=... ,
end=...)
Like find but raises ValueError when the substring is not found. |
|
|
int
|
rindex(s,
sub,
start=... ,
end=...)
Like rfind but raises ValueError when the substring is not found. |
|
|
int
|
count(s,
sub,
start=...,
end=...)
Return the number of occurrences of substring sub in string
s[start:end]. |
|
|
in
|
find(s,
sub,
start=... ,
end=...)
Return the lowest index in s where substring sub is found, such that
sub is contained within s[start,end]. |
|
|
int
|
rfind(s,
sub,
start=... ,
end=...)
Return the highest index in s where substring sub is found, such that
sub is contained within s[start,end]. |
|
|
float
|
atof(s)
Return the floating point number represented by the string s. |
|
|
int
|
atoi(s,
base=...)
Return the integer represented by the string s in the given base,
which defaults to 10. |
|
|
long
|
atol(s,
base=...)
Return the long integer represented by the string s in the given
base, which defaults to 10. |
|
|
string
|
ljust(s,
width,
fillchar=...)
Return a left-justified version of s, in a field of the specified
width, padded with spaces as needed. |
|
|
string
|
rjust(s,
width,
fillchar=...)
Return a right-justified version of s, in a field of the specified
width, padded with spaces as needed. |
|
|
string
|
center(s,
width,
fillchar=...)
Return a center version of s, in a field of the specified width. |
|
|
string
|
zfill(x,
width)
Pad a numeric string x with zeros on the left, to fill a field of the
specified width. |
|
|
string
|
expandtabs(s,
tabsize=...)
Return a copy of the string s with all tab characters replaced by the
appropriate number of spaces, depending on the current column, and
the tabsize (default 8). |
|
|
string
|
translate(s,
table,
deletions=...)
Return a copy of the string s, where all characters occurring in the
optional argument deletions are removed, and the remaining characters
have been mapped through the given translation table, which must be a
string of length 256. |
|
|
string
|
capitalize(s)
Return a copy of the string s with only its first character
capitalized. |
|
|
|
replace(s,
old,
new,
maxsplit=-1)
replace (str, old, new[, maxsplit]) -> string |
|
|