annotate Doc/lib/libstring.tex @ 33413:e1ab2c12cd5e legacy-trunk

Markup nits.
author Raymond Hettinger <python@rcn.com>
date Mon, 06 Sep 2004 01:01:08 +0000
parents 993fd8acc90f
children 301265b80c41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
1 \section{\module{string} ---
10703
e4e800a78d8d Make internal module references hyperlinks wherever it makes sense.
Fred Drake <fdrake@acm.org>
parents: 10229
diff changeset
2 Common string operations}
e4e800a78d8d Make internal module references hyperlinks wherever it makes sense.
Fred Drake <fdrake@acm.org>
parents: 10229
diff changeset
3
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8488
diff changeset
4 \declaremodule{standard}{string}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8488
diff changeset
5 \modulesynopsis{Common string operations.}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8488
diff changeset
6
33258
993fd8acc90f Ah whoops, we didn't turn string into a package (thanks Neal!)
Barry Warsaw <barry@python.org>
parents: 33257
diff changeset
7 The \module{string} module contains a number of useful constants and classes,
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
8 as well as some deprecated legacy functions that are also available as methods
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
9 on strings. See the module \refmodule{re}\refstmodindex{re} for string
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
10 functions based on regular expressions.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
12 \subsection{String constants}
2463
e764b78a704f add warning about strop
Guido van Rossum <guido@python.org>
parents: 2453
diff changeset
13
15665
1690755c5986 Fix doubled word
Andrew M. Kuchling <amk@amk.ca>
parents: 15009
diff changeset
14 The constants defined in this module are:
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
18776
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
16 \begin{datadesc}{ascii_letters}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
17 The concatenation of the \constant{ascii_lowercase} and
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
18 \constant{ascii_uppercase} constants described below. This value is
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
19 not locale-dependent.
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
20 \end{datadesc}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
21
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
22 \begin{datadesc}{ascii_lowercase}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
23 The lowercase letters \code{'abcdefghijklmnopqrstuvwxyz'}. This
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
24 value is not locale-dependent and will not change.
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
25 \end{datadesc}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
26
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
27 \begin{datadesc}{ascii_uppercase}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
28 The uppercase letters \code{'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}. This
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
29 value is not locale-dependent and will not change.
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
30 \end{datadesc}
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
31
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 \begin{datadesc}{digits}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 The string \code{'0123456789'}.
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 \begin{datadesc}{hexdigits}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 The string \code{'0123456789abcdefABCDEF'}.
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 \begin{datadesc}{letters}
12352
179a6e2850ac letters:
Fred Drake <fdrake@acm.org>
parents: 10882
diff changeset
41 The concatenation of the strings \constant{lowercase} and
18776
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
42 \constant{uppercase} described below. The specific value is
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
43 locale-dependent, and will be updated when
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
44 \function{locale.setlocale()} is called.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 \begin{datadesc}{lowercase}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 A string containing all the characters that are considered lowercase
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 letters. On most systems this is the string
2453
cdd3a721b40e a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents: 1789
diff changeset
50 \code{'abcdefghijklmnopqrstuvwxyz'}. Do not change its definition ---
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
51 the effect on the routines \function{upper()} and
18776
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
52 \function{swapcase()} is undefined. The specific value is
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
53 locale-dependent, and will be updated when
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
54 \function{locale.setlocale()} is called.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 \begin{datadesc}{octdigits}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 The string \code{'01234567'}.
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
14666
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
61 \begin{datadesc}{punctuation}
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
62 String of \ASCII{} characters which are considered punctuation
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
63 characters in the \samp{C} locale.
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
64 \end{datadesc}
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
65
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
66 \begin{datadesc}{printable}
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
67 String of characters which are considered printable. This is a
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
68 combination of \constant{digits}, \constant{letters},
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
69 \constant{punctuation}, and \constant{whitespace}.
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
70 \end{datadesc}
1570854911ce Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents: 14488
diff changeset
71
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 \begin{datadesc}{uppercase}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 A string containing all the characters that are considered uppercase
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 letters. On most systems this is the string
2453
cdd3a721b40e a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents: 1789
diff changeset
75 \code{'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}. Do not change its definition ---
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
76 the effect on the routines \function{lower()} and
18776
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
77 \function{swapcase()} is undefined. The specific value is
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
78 locale-dependent, and will be updated when
22b2f4b436af Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents: 17759
diff changeset
79 \function{locale.setlocale()} is called.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 \begin{datadesc}{whitespace}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 A string containing all characters that are considered whitespace.
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 On most systems this includes the characters space, tab, linefeed,
2453
cdd3a721b40e a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents: 1789
diff changeset
85 return, formfeed, and vertical tab. Do not change its definition ---
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
86 the effect on the routines \function{strip()} and \function{split()}
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
87 is undefined.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 \end{datadesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
90 \subsection{Template strings}
14488
aba7eb9d8d61 Add a reference to the material on string methods.
Fred Drake <fdrake@acm.org>
parents: 12976
diff changeset
91
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
92 Templates are Unicode strings that can be used to provide string substitutions
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
93 as described in \pep{292}. There is a \class{Template} class that is a
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
94 subclass of \class{unicode}, overriding the default \method{__mod__()} method.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
95 Instead of the normal \samp{\%}-based substitutions, Template strings support
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
96 \samp{\$}-based substitutions, using the following rules:
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
97
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
98 \begin{itemize}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
99 \item \samp{\$\$} is an escape; it is replaced with a single \samp{\$}.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
100
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
101 \item \samp{\$identifier} names a substitution placeholder matching a mapping
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
102 key of "identifier". By default, "identifier" must spell a Python
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
103 identifier. The first non-identifier character after the \samp{\$}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
104 character terminates this placeholder specification.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
105
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
106 \item \samp{\$\{identifier\}} is equivalent to \samp{\$identifier}. It is
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
107 required when valid identifier characters follow the placeholder but are
33413
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
108 not part of the placeholder, such as "\$\{noun\}ification".
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
109 \end{itemize}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
110
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
111 Any other appearance of \samp{\$} in the string will result in a
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
112 \exception{ValueError} being raised.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
113
33413
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
114 \versionadded{2.4}
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
115
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
116 Template strings are used just like normal strings, in that the modulus
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
117 operator is used to interpolate a dictionary of values into a Template string,
33413
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
118 for example:
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
119
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
120 \begin{verbatim}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
121 >>> from string import Template
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
122 >>> s = Template('$who likes $what')
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
123 >>> print s % dict(who='tim', what='kung pao')
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
124 tim likes kung pao
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
125 >>> Template('Give $who $100') % dict(who='tim')
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
126 Traceback (most recent call last):
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
127 [...]
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
128 ValueError: Invalid placeholder at index 10
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
129 \end{verbatim}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
130
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
131 There is also a \class{SafeTemplate} class, derived from \class{Template}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
132 which acts the same as \class{Template}, except that if placeholders are
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
133 missing in the interpolation dictionary, no \exception{KeyError} will be
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
134 raised. Instead the original placeholder (with or without the braces, as
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
135 appropriate) will be used:
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
136
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
137 \begin{verbatim}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
138 >>> from string import SafeTemplate
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
139 >>> s = SafeTemplate('$who likes $what for ${meal}')
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
140 >>> print s % dict(who='tim')
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
141 tim likes $what for ${meal}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
142 \end{verbatim}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
143
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
144 The values in the mapping will automatically be converted to Unicode strings,
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
145 using the built-in \function{unicode()} function, which will be called without
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
146 optional arguments \var{encoding} or \var{errors}.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
147
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
148 Advanced usage: you can derive subclasses of \class{Template} or
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
149 \class{SafeTemplate} to use application-specific placeholder rules. To do
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
150 this, you override the class attribute \member{pattern}; the value must be a
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
151 compiled regular expression object with four named capturing groups. The
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
152 capturing groups correspond to the rules given above, along with the invalid
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
153 placeholder rule:
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
154
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
155 \begin{itemize}
33413
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
156 \item \var{escaped} -- This group matches the escape sequence, \samp{\$\$},
33257
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
157 in the default pattern.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
158 \item \var{named} -- This group matches the unbraced placeholder name; it
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
159 should not include the \samp{\$} in capturing group.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
160 \item \var{braced} -- This group matches the brace delimited placeholder name;
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
161 it should not include either the \samp{\$} or braces in the capturing
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
162 group.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
163 \item \var{bogus} -- This group matches any other \samp{\$}. It usually just
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
164 matches a single \samp{\$} and should appear last.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
165 \end{itemize}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
166
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
167 \subsection{String functions}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
168
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
169 The following functions are available to operate on string and Unicode
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
170 objects. They are not available as string methods.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
171
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
172 \begin{funcdesc}{capwords}{s}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
173 Split the argument into words using \function{split()}, capitalize
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
174 each word using \function{capitalize()}, and join the capitalized
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
175 words using \function{join()}. Note that this replaces runs of
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
176 whitespace characters by a single space, and removes leading and
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
177 trailing whitespace.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
178 \end{funcdesc}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
179
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
180 \begin{funcdesc}{maketrans}{from, to}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
181 Return a translation table suitable for passing to
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
182 \function{translate()} or \function{regex.compile()}, that will map
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
183 each character in \var{from} into the character at the same position
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
184 in \var{to}; \var{from} and \var{to} must have the same length.
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
185
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
186 \warning{Don't use strings derived from \constant{lowercase}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
187 and \constant{uppercase} as arguments; in some locales, these don't have
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
188 the same length. For case conversions, always use
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
189 \function{lower()} and \function{upper()}.}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
190 \end{funcdesc}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
191
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
192 \subsection{Deprecated string functions}
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
193
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
194 The following list of functions are also defined as methods of string and
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
195 Unicode objects; see ``String Methods'' (section
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
196 \ref{string-methods}) for more information on those. You should consider
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
197 these functions as deprecated, although they will not be removed until Python
11a4fbc88a80 PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents: 32761
diff changeset
198 3.0. The functions defined in this module are:
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 \begin{funcdesc}{atof}{s}
15009
9847b486d15f Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents: 14710
diff changeset
201 \deprecated{2.0}{Use the \function{float()} built-in function.}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
202 Convert a string to a floating point number. The string must have
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
203 the standard syntax for a floating point literal in Python,
10229
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
204 optionally preceded by a sign (\samp{+} or \samp{-}). Note that
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
205 this behaves identical to the built-in function
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
206 \function{float()}\bifuncindex{float} when passed a string.
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
207
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 18776
diff changeset
208 \note{When passing in a string, values for NaN\index{NaN}
10229
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
209 and Infinity\index{Infinity} may be returned, depending on the
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
210 underlying C library. The specific set of strings accepted which
ce57eb30968a Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents: 10222
diff changeset
211 cause these values to be returned depends entirely on the C library
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 18776
diff changeset
212 and is known to vary.}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
215 \begin{funcdesc}{atoi}{s\optional{, base}}
15009
9847b486d15f Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents: 14710
diff changeset
216 \deprecated{2.0}{Use the \function{int()} built-in function.}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
217 Convert string \var{s} to an integer in the given \var{base}. The
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
218 string must consist of one or more digits, optionally preceded by a
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
219 sign (\samp{+} or \samp{-}). The \var{base} defaults to 10. If it
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
220 is 0, a default base is chosen depending on the leading characters
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
221 of the string (after stripping the sign): \samp{0x} or \samp{0X}
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
222 means 16, \samp{0} means 8, anything else means 10. If \var{base}
14710
ac6df0494c58 Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents: 14666
diff changeset
223 is 16, a leading \samp{0x} or \samp{0X} is always accepted, though
ac6df0494c58 Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents: 14666
diff changeset
224 not required. This behaves identically to the built-in function
ac6df0494c58 Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents: 14666
diff changeset
225 \function{int()} when passed a string. (Also note: for a more
ac6df0494c58 Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents: 14666
diff changeset
226 flexible interpretation of numeric literals, use the built-in
ac6df0494c58 Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents: 14666
diff changeset
227 function \function{eval()}\bifuncindex{eval}.)
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
230 \begin{funcdesc}{atol}{s\optional{, base}}
15009
9847b486d15f Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents: 14710
diff changeset
231 \deprecated{2.0}{Use the \function{long()} built-in function.}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
232 Convert string \var{s} to a long integer in the given \var{base}.
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
233 The string must consist of one or more digits, optionally preceded
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
234 by a sign (\samp{+} or \samp{-}). The \var{base} argument has the
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
235 same meaning as for \function{atoi()}. A trailing \samp{l} or
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
236 \samp{L} is not allowed, except if the base is 0. Note that when
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
237 invoked without \var{base} or with \var{base} set to 10, this
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
238 behaves identical to the built-in function
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
239 \function{long()}\bifuncindex{long} when passed a string.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
3996
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
242 \begin{funcdesc}{capitalize}{word}
23942
6e2a3c5700ac Make the docs for string.capitalize() match those of str.capitalize()
Fred Drake <fdrake@acm.org>
parents: 23225
diff changeset
243 Return a copy of \var{word} with only its first character capitalized.
3996
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
244 \end{funcdesc}
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
245
15009
9847b486d15f Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents: 14710
diff changeset
246 \begin{funcdesc}{expandtabs}{s\optional{, tabsize}}
33413
e1ab2c12cd5e Markup nits.
Raymond Hettinger <python@rcn.com>
parents: 33258
diff changeset
247 Expand tabs in a string replacing them by one or more spaces,
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
248 depending on the current column and the given tab size. The column
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
249 number is reset to zero after each newline occurring in the string.
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
250 This doesn't understand other non-printing characters or escape
9952
e5d0df824bf3 Document the default for tabsize in expandtabs().
Guido van Rossum <guido@python.org>
parents: 9675
diff changeset
251 sequences. The tab size defaults to 8.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
254 \begin{funcdesc}{find}{s, sub\optional{, start\optional{,end}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
255 Return the lowest index in \var{s} where the substring \var{sub} is
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
256 found such that \var{sub} is wholly contained in
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
257 \code{\var{s}[\var{start}:\var{end}]}. Return \code{-1} on failure.
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
258 Defaults for \var{start} and \var{end} and interpretation of
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
259 negative values is the same as for slices.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
261
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
262 \begin{funcdesc}{rfind}{s, sub\optional{, start\optional{, end}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
263 Like \function{find()} but find the highest index.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
265
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
266 \begin{funcdesc}{index}{s, sub\optional{, start\optional{, end}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
267 Like \function{find()} but raise \exception{ValueError} when the
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
268 substring is not found.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
270
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
271 \begin{funcdesc}{rindex}{s, sub\optional{, start\optional{, end}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
272 Like \function{rfind()} but raise \exception{ValueError} when the
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
273 substring is not found.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
275
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
276 \begin{funcdesc}{count}{s, sub\optional{, start\optional{, end}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
277 Return the number of (non-overlapping) occurrences of substring
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
278 \var{sub} in string \code{\var{s}[\var{start}:\var{end}]}.
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
279 Defaults for \var{start} and \var{end} and interpretation of
12976
f793c47c510e Minor grammatical fix
Andrew M. Kuchling <amk@amk.ca>
parents: 12352
diff changeset
280 negative values are the same as for slices.
1750
0b645726957e libsocket.tex: send[to] returns nbytes.
Guido van Rossum <guido@python.org>
parents: 1471
diff changeset
281 \end{funcdesc}
0b645726957e libsocket.tex: send[to] returns nbytes.
Guido van Rossum <guido@python.org>
parents: 1471
diff changeset
282
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 \begin{funcdesc}{lower}{s}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
284 Return a copy of \var{s}, but with upper case letters converted to
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
285 lower case.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
287
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
288 \begin{funcdesc}{split}{s\optional{, sep\optional{, maxsplit}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
289 Return a list of the words of the string \var{s}. If the optional
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
290 second argument \var{sep} is absent or \code{None}, the words are
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
291 separated by arbitrary strings of whitespace characters (space, tab,
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
292 newline, return, formfeed). If the second argument \var{sep} is
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
293 present and not \code{None}, it specifies a string to be used as the
10882
06def8042d8e Typo reported by Gerry Wiener <wiener@rap.ucar.edu>:
Fred Drake <fdrake@acm.org>
parents: 10703
diff changeset
294 word separator. The returned list will then have one more item
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
295 than the number of non-overlapping occurrences of the separator in
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
296 the string. The optional third argument \var{maxsplit} defaults to
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
297 0. If it is nonzero, at most \var{maxsplit} number of splits occur,
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
298 and the remainder of the string is returned as the final element of
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
299 the list (thus, the list will have at most \code{\var{maxsplit}+1}
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
300 elements).
31735
ee0ba00b277c Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31289
diff changeset
301
ee0ba00b277c Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31289
diff changeset
302 The behavior of split on an empty string depends on the value of \var{sep}.
ee0ba00b277c Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31289
diff changeset
303 If \var{sep} is not specified, or specified as \code{None}, the result will
ee0ba00b277c Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31289
diff changeset
304 be an empty list. If \var{sep} is specified as any string, the result will
ee0ba00b277c Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31289
diff changeset
305 be a list containing one element which is an empty string.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
307
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30937
diff changeset
308 \begin{funcdesc}{rsplit}{s\optional{, sep\optional{, maxsplit}}}
31206
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
309 Return a list of the words of the string \var{s}, scanning \var{s}
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
310 from the end. To all intents and purposes, the resulting list of
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
311 words is the same as returned by \function{split()}, except when the
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
312 optional third argument \var{maxsplit} is explicitly specified and
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
313 nonzero. When \var{maxsplit} is nonzero, at most \var{maxsplit}
31289
2cd96629fe8d fix truly evil markup typo
Fred Drake <fdrake@acm.org>
parents: 31206
diff changeset
314 number of splits -- the \emph{rightmost} ones -- occur, and the remainder
31206
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
315 of the string is returned as the first element of the list (thus, the
3771ff99d5f2 Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 31199
diff changeset
316 list will have at most \code{\var{maxsplit}+1} elements).
31199
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30937
diff changeset
317 \versionadded{2.4}
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30937
diff changeset
318 \end{funcdesc}
504943c89193 Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents: 30937
diff changeset
319
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
320 \begin{funcdesc}{splitfields}{s\optional{, sep\optional{, maxsplit}}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
321 This function behaves identically to \function{split()}. (In the
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
322 past, \function{split()} was only used with one argument, while
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
323 \function{splitfields()} was only used with two arguments.)
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
325
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
326 \begin{funcdesc}{join}{words\optional{, sep}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
327 Concatenate a list or tuple of words with intervening occurrences of
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
328 \var{sep}. The default value for \var{sep} is a single space
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
329 character. It is always true that
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
330 \samp{string.join(string.split(\var{s}, \var{sep}), \var{sep})}
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
331 equals \var{s}.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
333
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
334 \begin{funcdesc}{joinfields}{words\optional{, sep}}
25229
8775dee60d89 Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents: 23942
diff changeset
335 This function behaves identically to \function{join()}. (In the past,
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
336 \function{join()} was only used with one argument, while
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
337 \function{joinfields()} was only used with two arguments.)
25229
8775dee60d89 Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents: 23942
diff changeset
338 Note that there is no \method{joinfields()} method on string
8775dee60d89 Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents: 23942
diff changeset
339 objects; use the \method{join()} method instead.
3996
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
340 \end{funcdesc}
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
341
23225
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
342 \begin{funcdesc}{lstrip}{s\optional{, chars}}
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
343 Return a copy of the string with leading characters removed. If
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
344 \var{chars} is omitted or \code{None}, whitespace characters are
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
345 removed. If given and not \code{None}, \var{chars} must be a string;
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
346 the characters in the string will be stripped from the beginning of
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
347 the string this method is called on.
28575
215f1f4851a4 Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25229
diff changeset
348 \versionchanged[The \var{chars} parameter was added. The \var{chars}
215f1f4851a4 Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25229
diff changeset
349 parameter cannot be passed in earlier 2.2 versions]{2.2.3}
3996
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
350 \end{funcdesc}
0ec2ce97b8e3 Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents: 3858
diff changeset
351
23225
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
352 \begin{funcdesc}{rstrip}{s\optional{, chars}}
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
353 Return a copy of the string with trailing characters removed. If
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
354 \var{chars} is omitted or \code{None}, whitespace characters are
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
355 removed. If given and not \code{None}, \var{chars} must be a string;
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
356 the characters in the string will be stripped from the end of the
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
357 string this method is called on.
28575
215f1f4851a4 Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25229
diff changeset
358 \versionchanged[The \var{chars} parameter was added. The \var{chars}
32761
61be904a1d4e Patch #993187: Make rstrip doc similar to lstrip.
Martin v. Löwis <martin@v.loewis.de>
parents: 31735
diff changeset
359 parameter cannot be passed in earlier 2.2 versions]{2.2.3}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
361
23225
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
362 \begin{funcdesc}{strip}{s\optional{, chars}}
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
363 Return a copy of the string with leading and trailing characters
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
364 removed. If \var{chars} is omitted or \code{None}, whitespace
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
365 characters are removed. If given and not \code{None}, \var{chars}
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
366 must be a string; the characters in the string will be stripped from
e639e34ef901 Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents: 20580
diff changeset
367 the both ends of the string this method is called on.
28575
215f1f4851a4 Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents: 25229
diff changeset
368 \versionchanged[The \var{chars} parameter was added. The \var{chars}
28665
239429dc029f Oops, missed updating doc to correct version for split
Neal Norwitz <nnorwitz@gmail.com>
parents: 28575
diff changeset
369 parameter cannot be passed in earlier 2.2 versions]{2.2.3}
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
371
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 \begin{funcdesc}{swapcase}{s}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
373 Return a copy of \var{s}, but with lower case letters
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
374 converted to upper case and vice versa.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
376
3858
8b71ea5dacc8 Added maketrans() and optional 3rd arg to translate() (chars to delete).
Guido van Rossum <guido@python.org>
parents: 3379
diff changeset
377 \begin{funcdesc}{translate}{s, table\optional{, deletechars}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
378 Delete all characters from \var{s} that are in \var{deletechars} (if
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
379 present), and then translate the characters using \var{table}, which
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
380 must be a 256-character string giving the translation for each
29833
d45d317fda35 SF bug #706546: u''.translate not documented
Raymond Hettinger <python@rcn.com>
parents: 28665
diff changeset
381 character value, indexed by its ordinal.
3084
91c1bb75e945 added string.translate(s, table)
Guido van Rossum <guido@python.org>
parents: 2647
diff changeset
382 \end{funcdesc}
91c1bb75e945 added string.translate(s, table)
Guido van Rossum <guido@python.org>
parents: 2647
diff changeset
383
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 \begin{funcdesc}{upper}{s}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
385 Return a copy of \var{s}, but with lower case letters converted to
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
386 upper case.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
388
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
389 \begin{funcdesc}{ljust}{s, width}
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
390 \funcline{rjust}{s, width}
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
391 \funcline{center}{s, width}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
392 These functions respectively left-justify, right-justify and center
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
393 a string in a field of given width. They return a string that is at
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
394 least \var{width} characters wide, created by padding the string
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
395 \var{s} with spaces until the given width on the right, left or both
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
396 sides. The string is never truncated.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 \end{funcdesc}
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
398
7712
0cbc9df882b6 Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents: 7277
diff changeset
399 \begin{funcdesc}{zfill}{s, width}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
400 Pad a numeric string on the left with zero digits until the given
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
401 width is reached. Strings starting with a sign are handled
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
402 correctly.
1471
2ec96140a36b Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 \end{funcdesc}
2463
e764b78a704f add warning about strop
Guido van Rossum <guido@python.org>
parents: 2453
diff changeset
404
30937
51ebf5474f3d Patch #843088: Fix typos. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents: 29893
diff changeset
405 \begin{funcdesc}{replace}{str, old, new\optional{, maxreplace}}
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
406 Return a copy of string \var{str} with all occurrences of substring
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
407 \var{old} replaced by \var{new}. If the optional argument
30937
51ebf5474f3d Patch #843088: Fix typos. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents: 29893
diff changeset
408 \var{maxreplace} is given, the first \var{maxreplace} occurrences are
9675
b78049fefceb Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents: 8918
diff changeset
409 replaced.
5212
1f38d5fb3d23 Added docs for replace() and replace1().
Guido van Rossum <guido@python.org>
parents: 5188
diff changeset
410 \end{funcdesc}