Clarify descriptions of some operations; it's not always clear that

strings are not actually modified.  Problem reported by Dr. Peter
Stoehr <peter.stoehr@weihenstephan.org>.
This commit is contained in:
Fred Drake 1998-12-21 18:56:13 +00:00
parent 3b02ddfa41
commit e848976fba
1 changed files with 107 additions and 103 deletions

View File

@ -58,35 +58,36 @@ The functions defined in this module are:
\begin{funcdesc}{atof}{s}
Convert a string to a floating point number. The string must have
the standard syntax for a floating point literal in Python, optionally
preceded by a sign (\samp{+} or \samp{-}). Note that this behaves
identical to the built-in function
the standard syntax for a floating point literal in Python,
optionally preceded by a sign (\samp{+} or \samp{-}). Note that
this behaves identical to the built-in function
\function{float()}\bifuncindex{float} when passed a string.
\end{funcdesc}
\begin{funcdesc}{atoi}{s\optional{, base}}
Convert string \var{s} to an integer in the given \var{base}. The
string must consist of one or more digits, optionally preceded by a
sign (\samp{+} or \samp{-}). The \var{base} defaults to 10. If it is
0, a default base is chosen depending on the leading characters of the
string (after stripping the sign): \samp{0x} or \samp{0X} means 16,
\samp{0} means 8, anything else means 10. If \var{base} is 16, a
leading \samp{0x} or \samp{0X} is always accepted. Note that when
invoked without \var{base} or with \var{base} set to 10, this behaves
identical to the built-in function \function{int()} when passed a string.
(Also note: for a more flexible interpretation of numeric literals,
use the built-in function \function{eval()}\bifuncindex{eval}.)
sign (\samp{+} or \samp{-}). The \var{base} defaults to 10. If it
is 0, a default base is chosen depending on the leading characters
of the string (after stripping the sign): \samp{0x} or \samp{0X}
means 16, \samp{0} means 8, anything else means 10. If \var{base}
is 16, a leading \samp{0x} or \samp{0X} is always accepted. Note
that when invoked without \var{base} or with \var{base} set to 10,
this behaves identical to the built-in function \function{int()}
when passed a string. (Also note: for a more flexible
interpretation of numeric literals, use the built-in function
\function{eval()}\bifuncindex{eval}.)
\end{funcdesc}
\begin{funcdesc}{atol}{s\optional{, base}}
Convert string \var{s} to a long integer in the given \var{base}. The
string must consist of one or more digits, optionally preceded by a
sign (\samp{+} or \samp{-}). The \var{base} argument has the same
meaning as for \function{atoi()}. A trailing \samp{l} or \samp{L} is
not allowed, except if the base is 0. Note that when invoked without
\var{base} or with \var{base} set to 10, this behaves identical to the
built-in function \function{long()}\bifuncindex{long} when passed a
string.
Convert string \var{s} to a long integer in the given \var{base}.
The string must consist of one or more digits, optionally preceded
by a sign (\samp{+} or \samp{-}). The \var{base} argument has the
same meaning as for \function{atoi()}. A trailing \samp{l} or
\samp{L} is not allowed, except if the base is 0. Note that when
invoked without \var{base} or with \var{base} set to 10, this
behaves identical to the built-in function
\function{long()}\bifuncindex{long} when passed a string.
\end{funcdesc}
\begin{funcdesc}{capitalize}{word}
@ -113,8 +114,8 @@ sequences.
Return the lowest index in \var{s} where the substring \var{sub} is
found such that \var{sub} is wholly contained in
\code{\var{s}[\var{start}:\var{end}]}. Return \code{-1} on failure.
Defaults for \var{start} and \var{end} and interpretation of negative
values is the same as for slices.
Defaults for \var{start} and \var{end} and interpretation of
negative values is the same as for slices.
\end{funcdesc}
\begin{funcdesc}{rfind}{s, sub\optional{, start\optional{, end}}}
@ -134,12 +135,13 @@ substring is not found.
\begin{funcdesc}{count}{s, sub\optional{, start\optional{, end}}}
Return the number of (non-overlapping) occurrences of substring
\var{sub} in string \code{\var{s}[\var{start}:\var{end}]}.
Defaults for \var{start} and \var{end} and interpretation of negative
values is the same as for slices.
Defaults for \var{start} and \var{end} and interpretation of
negative values is the same as for slices.
\end{funcdesc}
\begin{funcdesc}{lower}{s}
Convert letters to lower case.
Return a copy of \var{s}, but with upper case letters converted to
lower case.
\end{funcdesc}
\begin{funcdesc}{maketrans}{from, to}
@ -148,10 +150,10 @@ Return a translation table suitable for passing to
each character in \var{from} into the character at the same position
in \var{to}; \var{from} and \var{to} must have the same length.
\strong{Warning:} don't use strings derived from \code{lowercase} and
\code{uppercase} as arguments; in some locales, these don't have the
same length. For case conversions, always use \function{lower()} and
\function{upper()}.
\strong{Warning:} don't use strings derived from \code{lowercase}
and \code{uppercase} as arguments; in some locales, these don't have
the same length. For case conversions, always use
\function{lower()} and \function{upper()}.
\end{funcdesc}
\begin{funcdesc}{split}{s\optional{, sep\optional{, maxsplit}}}
@ -160,12 +162,13 @@ second argument \var{sep} is absent or \code{None}, the words are
separated by arbitrary strings of whitespace characters (space, tab,
newline, return, formfeed). If the second argument \var{sep} is
present and not \code{None}, it specifies a string to be used as the
word separator. The returned list will then have one more items than
the number of non-overlapping occurrences of the separator in the
string. The optional third argument \var{maxsplit} defaults to 0. If
it is nonzero, at most \var{maxsplit} number of splits occur, and the
remainder of the string is returned as the final element of the list
(thus, the list will have at most \code{\var{maxsplit}+1} elements).
word separator. The returned list will then have one more items
than the number of non-overlapping occurrences of the separator in
the string. The optional third argument \var{maxsplit} defaults to
0. If it is nonzero, at most \var{maxsplit} number of splits occur,
and the remainder of the string is returned as the final element of
the list (thus, the list will have at most \code{\var{maxsplit}+1}
elements).
\end{funcdesc}
\begin{funcdesc}{splitfields}{s\optional{, sep\optional{, maxsplit}}}
@ -189,19 +192,21 @@ This function behaves identical to \function{join()}. (In the past,
\end{funcdesc}
\begin{funcdesc}{lstrip}{s}
Remove leading whitespace from the string \var{s}.
Return a copy of \var{s} but without leading whitespace characters.
\end{funcdesc}
\begin{funcdesc}{rstrip}{s}
Remove trailing whitespace from the string \var{s}.
Return a copy of \var{s} but without trailing whitespace
characters.
\end{funcdesc}
\begin{funcdesc}{strip}{s}
Remove leading and trailing whitespace from the string \var{s}.
Return a copy of \var{s} without leading or trailing whitespace.
\end{funcdesc}
\begin{funcdesc}{swapcase}{s}
Convert lower case letters to upper case and vice versa.
Return a copy of \var{s}, but with lower case letters
converted to upper case and vice versa.
\end{funcdesc}
\begin{funcdesc}{translate}{s, table\optional{, deletechars}}
@ -212,25 +217,24 @@ character value, indexed by its ordinal.
\end{funcdesc}
\begin{funcdesc}{upper}{s}
Convert letters to upper case.
Return a copy of \var{s}, but with lower case letters converted to
upper case.
\end{funcdesc}
\begin{funcdesc}{ljust}{s, width}
\funcline{rjust}{s, width}
\funcline{center}{s, width}
These functions respectively left-justify, right-justify and center a
string in a field of given width.
They return a string that is at least
\var{width}
characters wide, created by padding the string
\var{s}
with spaces until the given width on the right, left or both sides.
The string is never truncated.
These functions respectively left-justify, right-justify and center
a string in a field of given width. They return a string that is at
least \var{width} characters wide, created by padding the string
\var{s} with spaces until the given width 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 digits until the given
width is reached. Strings starting with a sign are handled correctly.
width is reached. Strings starting with a sign are handled
correctly.
\end{funcdesc}
\begin{funcdesc}{replace}{str, old, new\optional{, maxsplit}}