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
|
atof(s)
Return the floating point number represented by the string s. |
source code
|
|
|
atoi(s,
base=...)
Return the integer represented by the string s in the given
base, which defaults to 10. |
source code
|
|
|
atol(s,
base=...)
Return the long integer represented by the string s in the
given base, which defaults to 10. |
source code
|
|
|
|
|
|
|
center(s,
width,
fillchar=...)
Return a center version of s, in a field of the specified
width. |
source code
|
|
|
count(s,
sub,
start=...,
end=...)
Return the number of occurrences of substring sub in string
s[start:end]. |
source code
|
|
|
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). |
source code
|
|
|
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]. |
source code
|
|
|
index(s,
sub,
start=... ,
end=...)
Like find but raises ValueError when the substring is not found. |
source code
|
|
|
join(list,
sep=...)
Return a string composed of the words in list, with
intervening occurrences of sep. |
source code
|
|
|
joinfields(list,
sep=...)
Return a string composed of the words in list, with
intervening occurrences of sep. |
source code
|
|
|
ljust(s,
width,
fillchar=...)
Return a left-justified version of s, in a field of the
specified width, padded with spaces as needed. |
source code
|
|
|
|
|
lstrip(s,
chars=...)
Return a copy of the string s with leading whitespace removed. |
source code
|
|
|
replace(s,
old,
new,
maxsplit=-1)
replace (str, old, new[, maxsplit]) -> string |
source code
|
|
|
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]. |
source code
|
|
|
rindex(s,
sub,
start=... ,
end=...)
Like rfind but raises ValueError when the substring is not found. |
source code
|
|
|
rjust(s,
width,
fillchar=...)
Return a right-justified version of s, in a field of the
specified width, padded with spaces as needed. |
source code
|
|
|
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. |
source code
|
|
|
rstrip(s,
chars=...)
Return a copy of the string s with trailing whitespace removed. |
source code
|
|
|
split(s,
sep=... ,
maxsplit=...)
Return a list of the words in the string s, using sep as the
delimiter string. |
source code
|
|
|
splitfields(s,
sep=... ,
maxsplit=...)
Return a list of the words in the string s, using sep as the
delimiter string. |
source code
|
|
|
strip(s,
chars=...)
Return a copy of the string s with leading and trailing
whitespace removed. |
source code
|
|
|
swapcase(s)
Return a copy of the string s with upper case characters
converted to lowercase and vice versa. |
source code
|
|
|
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. |
source code
|
|
|
|
|
zfill(x,
width)
Pad a numeric string x with zeros on the left, to fill a field
of the specified width. |
source code
|
|