Standard Module string

string

This module defines some constants useful for checking character classes and some useful string functions. See the modules regex and regsub for string functions based on regular expressions.

The constants defined in this module are are:


\begin{datadesc}{digits}
The string \code{'0123456789'}.
\end{datadesc}


\begin{datadesc}{hexdigits}
The string \code{'0123456789abcdefABCDEF'}.
\end{datadesc}


\begin{datadesc}{letters}
The concatenation of the strings \code{lowercase} and
\code{uppercase} described below.
\end{datadesc}


\begin{datadesc}{lowercase}
A string containing all the characters that are con...
...t on the routines \code{upper} and \code{swapcase} is
undefined.
\end{datadesc}


\begin{datadesc}{octdigits}
The string \code{'01234567'}.
\end{datadesc}


\begin{datadesc}{uppercase}
A string containing all the characters that are con...
...t on the routines \code{lower} and \code{swapcase} is
undefined.
\end{datadesc}


\begin{datadesc}{whitespace}
A string containing all characters that are consid...
...fect on the routines \code{strip} and \code{split} is
undefined.
\end{datadesc}

The functions defined in this module are:


\begin{funcdesc}{atof}{s}
Convert a string to a floating point number. The strin...
... in Python, optionally
preceded by a sign (\samp{+} or \samp{-}).
\end{funcdesc}


\begin{funcdesc}{atoi}{s\optional{\, base}}
Convert string \var{s} to an integer...
...als, use the built-in function
\code{eval()}.)
\bifuncindex{eval}
\end{funcdesc}


\begin{funcdesc}{atol}{s\optional{\, base}}
Convert string \var{s} to a long int...
...ing \samp{l} or \samp{L} is not
allowed, except if the base is 0.
\end{funcdesc}


\begin{funcdesc}{capitalize}{word}
Capitalize the first character of the argument.
\end{funcdesc}


\begin{funcdesc}{capwords}{s}
Split the argument into words using \code{split}, ...
...'t change the delimiters, and lets you specify a word
separator.)
\end{funcdesc}


\begin{funcdesc}{expandtabs}{s\, tabsize}
Expand tabs in a string, i.e.\ replace...
...n't understand other non-printing characters or escape
sequences.
\end{funcdesc}


\begin{funcdesc}{find}{s\, sub\optional{\, start}}
Return the lowest index in \v...
...ode{0}. If \var{start} is
negative, \code{len(\var{s})} is added.
\end{funcdesc}


\begin{funcdesc}{rfind}{s\, sub\optional{\, start}}
Like \code{find} but find the highest index.
\end{funcdesc}


\begin{funcdesc}{index}{s\, sub\optional{\, start}}
Like \code{find} but raise \code{ValueError} when the substring is
not found.
\end{funcdesc}


\begin{funcdesc}{rindex}{s\, sub\optional{\, start}}
Like \code{rfind} but raise \code{ValueError} when the substring is
not found.
\end{funcdesc}


\begin{funcdesc}{count}{s\, sub\optional{\, start}}
Return the number of (non-ov...
...ode{0}. If \var{start} is
negative, \code{len(\var{s})} is added.
\end{funcdesc}


\begin{funcdesc}{lower}{s}
Convert letters to lower case.
\end{funcdesc}


\begin{funcdesc}{maketrans}{from, to}
Return a translation table suitable for pa...
... in \var{to}; \var{from} and
\var{to} must have the same length.
\end{funcdesc}


\begin{funcdesc}{split}{s\optional{\, sep\optional{\, maxsplit}}}
Return a list ...
...on that allows specifying a
regular expression as the separator.)
\end{funcdesc}


\begin{funcdesc}{splitfields}{s\optional{\, sep\optional{\, maxsplit}}}
This fun...
...ment, while \code{splitfields}
was only used with two arguments.)
\end{funcdesc}


\begin{funcdesc}{join}{words\optional{\, sep}}
Concatenate a list or tuple of wo...
...oin(string.split(\var{s}, \var{sep}), \var{sep})}
equals \var{s}.
\end{funcdesc}


\begin{funcdesc}{joinfields}{words\optional{\, sep}}
This function behaves ident...
...ument, while \code{joinfields}
was only used with two arguments.)
\end{funcdesc}


\begin{funcdesc}{lstrip}{s}
Remove leading whitespace from the string \var{s}.
\end{funcdesc}


\begin{funcdesc}{rstrip}{s}
Remove trailing whitespace from the string \var{s}.
\end{funcdesc}


\begin{funcdesc}{strip}{s}
Remove leading and trailing whitespace from the string \var{s}.
\end{funcdesc}


\begin{funcdesc}{swapcase}{s}
Convert lower case letters to upper case and vice versa.
\end{funcdesc}


\begin{funcdesc}{translate}{s, table\optional{, deletechars}}
Delete all charact...
...he translation for each character
value, indexed by its ordinal.
\end{funcdesc}


\begin{funcdesc}{upper}{s}
Convert letters to upper case.
\end{funcdesc}


\begin{funcdesc}{ljust}{s\, width}
\funcline{rjust}{s\, width}
\funcline{center}...
... on the right, left or both sides.
The string is never truncated.
\end{funcdesc}


\begin{funcdesc}{zfill}{s\, width}
Pad a numeric string on the left with zero di...
...h is reached. Strings starting with a sign are handled correctly.
\end{funcdesc}

This module is implemented in Python. Much of its functionality has been reimplemented in the built-in module strop. However, you should never import the latter module directly. When string discovers that strop exists, it transparently replaces parts of itself with the implementation from strop. After initialization, there is no overhead in using string instead of strop. strop