string

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.

Public module variables:

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

Functions

atof((s) -> float) Return the floating point number represented by the string s.
atoi((s [,base]) -> int) Return the integer represented by the string s in the given base, which defaults to 10.
atol((s [,base]) -> long) Return the long integer represented by the string s in the given base, which defaults to 10.
capitalize((s) -> string) Return a copy of the string s with only its first character capitalized.
capwords((s [,sep]) -> string) Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join.
center((s, width[, fillchar]) -> string) Return a center version of s, in a field of the specified width.
count((s, sub[, start[,end]]) -> int) Return the number of occurrences of substring sub in string s[start:end].
expandtabs((s [,tabsize]) -> string) 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).
find((s, sub [,start [,end]]) -> in) Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end].
index((s, sub [,start [,end]]) -> int) Like find but raises ValueError when the substring is not found.
join((list [,sep]) -> string) Return a string composed of the words in list, with intervening occurrences of sep.
joinfields(words[, sep]) join(list [,sep]) -> string
ljust((s, width[, fillchar]) -> string) Return a left-justified version of s, in a field of the specified width, padded with spaces as needed.
lower((s) -> string) Return a copy of the string s converted to lowercase.
lstrip((s [,chars]) -> string) Return a copy of the string s with leading whitespace removed.
maketrans((frm, to) -> string) Return a translation table (a string of 256 bytes long) suitable for use in string.translate.
replace((str, old, new[, maxreplace]) -> string) Return a copy of string str with all occurrences of substring old replaced by new.
rfind((s, sub [,start [,end]]) -> int) Return the highest index in s where substring sub is found, such that sub is contained within s[start,end].
rindex((s, sub [,start [,end]]) -> int) Like rfind but raises ValueError when the substring is not found.
rjust((s, width[, fillchar]) -> string) Return a right-justified version of s, in a field of the specified width, padded with spaces as needed.
rsplit((s [,sep [,maxsplit]]) -> list of strings) 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.
rstrip((s [,chars]) -> string) Return a copy of the string s with trailing whitespace removed.
split((s [,sep [,maxsplit]]) -> list of strings) Return a list of the words in the string s, using sep as the delimiter string.
splitfields(s[, sep, maxsplit]) split(s [,sep [,maxsplit]]) -> list of strings
strip((s [,chars]) -> string) Return a copy of the string s with leading and trailing whitespace removed.
swapcase((s) -> string) Return a copy of the string s with upper case characters converted to lowercase and vice versa.
translate((s,table [,deletions]) -> string) 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.
upper((s) -> string) Return a copy of the string s converted to uppercase.
zfill((x, width) -> string) Pad a numeric string x with zeros on the left, to fill a field of the specified width.

Classes

Formatter
Template(template) A string class for supporting $-substitutions.

Exceptions

atof_error alias of ValueError
atoi_error alias of ValueError
atol_error alias of ValueError
index_error alias of ValueError