Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / string-methods.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="typesseq-strings.html" />
13<link rel="prev" href="typesseq.html" />
14<link rel="parent" href="typesseq.html" />
15<link rel="next" href="typesseq-strings.html" />
16<meta name='aesop' content='information' />
17<title>2.3.6.1 String Methods </title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="2.3.6 Sequence Types "
25 href="typesseq.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="2.3.6 Sequence Types "
28 href="typesseq.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="2.3.6.2 String Formatting Operations"
31 href="typesseq-strings.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="typesseq.html">2.3.6 Sequence Types </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="typesseq.html">2.3.6 Sequence Types </A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="typesseq-strings.html">2.3.6.2 String Formatting Operations</A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H3><A NAME="SECTION004361000000000000000"></A><A NAME="string-methods"></A>
56<BR>
572.3.6.1 String Methods
58</H3>
59
60<P>
61These are the string methods which both 8-bit strings and Unicode
62objects support:
63
64<P>
65<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
66 <td><nobr><b><tt id='l2h-176' xml:id='l2h-176' class="method">capitalize</tt></b>(</nobr></td>
67 <td><var></var>)</td></tr></table></dt>
68<dd>
69Return a copy of the string with only its first character capitalized.
70
71<P>
72For 8-bit strings, this method is locale-dependent.
73</dl>
74
75<P>
76<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
77 <td><nobr><b><tt id='l2h-177' xml:id='l2h-177' class="method">center</tt></b>(</nobr></td>
78 <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
79<dd>
80Return centered in a string of length <var>width</var>. Padding is done
81using the specified <var>fillchar</var> (default is a space).
82
83<span class="versionnote">Changed in version 2.4:
84Support for the <var>fillchar</var> argument.</span>
85
86</dl>
87
88<P>
89<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
90 <td><nobr><b><tt id='l2h-178' xml:id='l2h-178' class="method">count</tt></b>(</nobr></td>
91 <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
92<dd>
93Return the number of occurrences of substring <var>sub</var> in string
94S<code>[<var>start</var>:<var>end</var>]</code>. Optional arguments <var>start</var> and
95<var>end</var> are interpreted as in slice notation.
96</dl>
97
98<P>
99<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
100 <td><nobr><b><tt id='l2h-179' xml:id='l2h-179' class="method">decode</tt></b>(</nobr></td>
101 <td><var></var><big>[</big><var>encoding</var><big>[</big><var>, errors</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
102<dd>
103Decodes the string using the codec registered for <var>encoding</var>.
104<var>encoding</var> defaults to the default string encoding. <var>errors</var>
105may be given to set a different error handling scheme. The default is
106<code>'strict'</code>, meaning that encoding errors raise
107<tt class="exception">UnicodeError</tt>. Other possible values are <code>'ignore'</code>,
108<code>'replace'</code> and any other name registered via
109<tt class="function">codecs.register_error</tt>.
110
111<span class="versionnote">New in version 2.2.</span>
112
113<span class="versionnote">Changed in version 2.3:
114Support for other error handling schemes added.</span>
115
116</dl>
117
118<P>
119<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
120 <td><nobr><b><tt id='l2h-180' xml:id='l2h-180' class="method">encode</tt></b>(</nobr></td>
121 <td><var></var><big>[</big><var>encoding</var><big>[</big><var>,errors</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
122<dd>
123Return an encoded version of the string. Default encoding is the current
124default string encoding. <var>errors</var> may be given to set a different
125error handling scheme. The default for <var>errors</var> is
126<code>'strict'</code>, meaning that encoding errors raise a
127<tt class="exception">UnicodeError</tt>. Other possible values are <code>'ignore'</code>,
128<code>'replace'</code>, <code>'xmlcharrefreplace'</code>, <code>'backslashreplace'</code>
129and any other name registered via <tt class="function">codecs.register_error</tt>.
130For a list of possible encodings, see section&nbsp;<A href="standard-encodings.html#standard-encodings">4.9.2</A>.
131
132<span class="versionnote">New in version 2.0.</span>
133
134<span class="versionnote">Changed in version 2.3:
135Support for <code>'xmlcharrefreplace'</code> and
136<code>'backslashreplace'</code> and other error handling schemes added.</span>
137
138</dl>
139
140<P>
141<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
142 <td><nobr><b><tt id='l2h-181' xml:id='l2h-181' class="method">endswith</tt></b>(</nobr></td>
143 <td><var>suffix</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
144<dd>
145Return <code>True</code> if the string ends with the specified <var>suffix</var>,
146otherwise return <code>False</code>. With optional <var>start</var>, test beginning at
147that position. With optional <var>end</var>, stop comparing at that position.
148</dl>
149
150<P>
151<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
152 <td><nobr><b><tt id='l2h-182' xml:id='l2h-182' class="method">expandtabs</tt></b>(</nobr></td>
153 <td><var></var><big>[</big><var>tabsize</var><big>]</big><var></var>)</td></tr></table></dt>
154<dd>
155Return a copy of the string where all tab characters are expanded
156using spaces. If <var>tabsize</var> is not given, a tab size of <code>8</code>
157characters is assumed.
158</dl>
159
160<P>
161<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
162 <td><nobr><b><tt id='l2h-183' xml:id='l2h-183' class="method">find</tt></b>(</nobr></td>
163 <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
164<dd>
165Return the lowest index in the string where substring <var>sub</var> is
166found, such that <var>sub</var> is contained in the range [<var>start</var>,
167<var>end</var>). Optional arguments <var>start</var> and <var>end</var> are
168interpreted as in slice notation. Return <code>-1</code> if <var>sub</var> is
169not found.
170</dl>
171
172<P>
173<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
174 <td><nobr><b><tt id='l2h-184' xml:id='l2h-184' class="method">index</tt></b>(</nobr></td>
175 <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
176<dd>
177Like <tt class="method">find()</tt>, but raise <tt class="exception">ValueError</tt> when the
178substring is not found.
179</dl>
180
181<P>
182<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
183 <td><nobr><b><tt id='l2h-185' xml:id='l2h-185' class="method">isalnum</tt></b>(</nobr></td>
184 <td><var></var>)</td></tr></table></dt>
185<dd>
186Return true if all characters in the string are alphanumeric and there
187is at least one character, false otherwise.
188
189<P>
190For 8-bit strings, this method is locale-dependent.
191</dl>
192
193<P>
194<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
195 <td><nobr><b><tt id='l2h-186' xml:id='l2h-186' class="method">isalpha</tt></b>(</nobr></td>
196 <td><var></var>)</td></tr></table></dt>
197<dd>
198Return true if all characters in the string are alphabetic and there
199is at least one character, false otherwise.
200
201<P>
202For 8-bit strings, this method is locale-dependent.
203</dl>
204
205<P>
206<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
207 <td><nobr><b><tt id='l2h-187' xml:id='l2h-187' class="method">isdigit</tt></b>(</nobr></td>
208 <td><var></var>)</td></tr></table></dt>
209<dd>
210Return true if all characters in the string are digits and there
211is at least one character, false otherwise.
212
213<P>
214For 8-bit strings, this method is locale-dependent.
215</dl>
216
217<P>
218<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
219 <td><nobr><b><tt id='l2h-188' xml:id='l2h-188' class="method">islower</tt></b>(</nobr></td>
220 <td><var></var>)</td></tr></table></dt>
221<dd>
222Return true if all cased characters in the string are lowercase and
223there is at least one cased character, false otherwise.
224
225<P>
226For 8-bit strings, this method is locale-dependent.
227</dl>
228
229<P>
230<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
231 <td><nobr><b><tt id='l2h-189' xml:id='l2h-189' class="method">isspace</tt></b>(</nobr></td>
232 <td><var></var>)</td></tr></table></dt>
233<dd>
234Return true if there are only whitespace characters in the string and
235there is at least one character, false otherwise.
236
237<P>
238For 8-bit strings, this method is locale-dependent.
239</dl>
240
241<P>
242<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
243 <td><nobr><b><tt id='l2h-190' xml:id='l2h-190' class="method">istitle</tt></b>(</nobr></td>
244 <td><var></var>)</td></tr></table></dt>
245<dd>
246Return true if the string is a titlecased string and there is at least one
247character, for example uppercase characters may only follow uncased
248characters and lowercase characters only cased ones. Return false
249otherwise.
250
251<P>
252For 8-bit strings, this method is locale-dependent.
253</dl>
254
255<P>
256<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
257 <td><nobr><b><tt id='l2h-191' xml:id='l2h-191' class="method">isupper</tt></b>(</nobr></td>
258 <td><var></var>)</td></tr></table></dt>
259<dd>
260Return true if all cased characters in the string are uppercase and
261there is at least one cased character, false otherwise.
262
263<P>
264For 8-bit strings, this method is locale-dependent.
265</dl>
266
267<P>
268<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
269 <td><nobr><b><tt id='l2h-192' xml:id='l2h-192' class="method">join</tt></b>(</nobr></td>
270 <td><var>seq</var>)</td></tr></table></dt>
271<dd>
272Return a string which is the concatenation of the strings in the
273sequence <var>seq</var>. The separator between elements is the string
274providing this method.
275</dl>
276
277<P>
278<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
279 <td><nobr><b><tt id='l2h-193' xml:id='l2h-193' class="method">ljust</tt></b>(</nobr></td>
280 <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
281<dd>
282Return the string left justified in a string of length <var>width</var>.
283Padding is done using the specified <var>fillchar</var> (default is a
284space). The original string is returned if
285<var>width</var> is less than <code>len(<var>s</var>)</code>.
286
287<span class="versionnote">Changed in version 2.4:
288Support for the <var>fillchar</var> argument.</span>
289
290</dl>
291
292<P>
293<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
294 <td><nobr><b><tt id='l2h-194' xml:id='l2h-194' class="method">lower</tt></b>(</nobr></td>
295 <td><var></var>)</td></tr></table></dt>
296<dd>
297Return a copy of the string converted to lowercase.
298
299<P>
300For 8-bit strings, this method is locale-dependent.
301</dl>
302
303<P>
304<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
305 <td><nobr><b><tt id='l2h-195' xml:id='l2h-195' class="method">lstrip</tt></b>(</nobr></td>
306 <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
307<dd>
308Return a copy of the string with leading characters removed. The
309<var>chars</var> argument is a string specifying the set of characters
310to be removed. If omitted or <code>None</code>, the <var>chars</var> argument
311defaults to removing whitespace. The <var>chars</var> argument is not
312a prefix; rather, all combinations of its values are stripped:
313<div class="verbatim"><pre>
314 &gt;&gt;&gt; ' spacious '.lstrip()
315 'spacious '
316 &gt;&gt;&gt; 'www.example.com'.lstrip('cmowz.')
317 'example.com'
318</pre></div>
319
320<span class="versionnote">Changed in version 2.2.2:
321Support for the <var>chars</var> argument.</span>
322
323</dl>
324
325<P>
326<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
327 <td><nobr><b><tt id='l2h-196' xml:id='l2h-196' class="method">replace</tt></b>(</nobr></td>
328 <td><var>old, new</var><big>[</big><var>, count</var><big>]</big><var></var>)</td></tr></table></dt>
329<dd>
330Return a copy of the string with all occurrences of substring
331<var>old</var> replaced by <var>new</var>. If the optional argument
332<var>count</var> is given, only the first <var>count</var> occurrences are
333replaced.
334</dl>
335
336<P>
337<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
338 <td><nobr><b><tt id='l2h-197' xml:id='l2h-197' class="method">rfind</tt></b>(</nobr></td>
339 <td><var>sub </var><big>[</big><var>,start </var><big>[</big><var>,end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
340<dd>
341Return the highest index in the string where substring <var>sub</var> is
342found, such that <var>sub</var> is contained within s[start,end]. Optional
343arguments <var>start</var> and <var>end</var> are interpreted as in slice
344notation. Return <code>-1</code> on failure.
345</dl>
346
347<P>
348<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
349 <td><nobr><b><tt id='l2h-198' xml:id='l2h-198' class="method">rindex</tt></b>(</nobr></td>
350 <td><var>sub</var><big>[</big><var>, start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
351<dd>
352Like <tt class="method">rfind()</tt> but raises <tt class="exception">ValueError</tt> when the
353substring <var>sub</var> is not found.
354</dl>
355
356<P>
357<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
358 <td><nobr><b><tt id='l2h-199' xml:id='l2h-199' class="method">rjust</tt></b>(</nobr></td>
359 <td><var>width</var><big>[</big><var>, fillchar</var><big>]</big><var></var>)</td></tr></table></dt>
360<dd>
361Return the string right justified in a string of length <var>width</var>.
362Padding is done using the specified <var>fillchar</var> (default is a space).
363The original string is returned if
364<var>width</var> is less than <code>len(<var>s</var>)</code>.
365
366<span class="versionnote">Changed in version 2.4:
367Support for the <var>fillchar</var> argument.</span>
368
369</dl>
370
371<P>
372<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
373 <td><nobr><b><tt id='l2h-200' xml:id='l2h-200' class="method">rsplit</tt></b>(</nobr></td>
374 <td><var></var><big>[</big><var>sep </var><big>[</big><var>,maxsplit</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
375<dd>
376Return a list of the words in the string, using <var>sep</var> as the
377delimiter string. If <var>maxsplit</var> is given, at most <var>maxsplit</var>
378splits are done, the <em>rightmost</em> ones. If <var>sep</var> is not specified
379or <code>None</code>, any whitespace string is a separator. Except for splitting
380from the right, <tt class="method">rsplit()</tt> behaves like <tt class="method">split()</tt> which
381is described in detail below.
382
383<span class="versionnote">New in version 2.4.</span>
384
385</dl>
386
387<P>
388<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
389 <td><nobr><b><tt id='l2h-201' xml:id='l2h-201' class="method">rstrip</tt></b>(</nobr></td>
390 <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
391<dd>
392Return a copy of the string with trailing characters removed. The
393<var>chars</var> argument is a string specifying the set of characters
394to be removed. If omitted or <code>None</code>, the <var>chars</var> argument
395defaults to removing whitespace. The <var>chars</var> argument is not
396a suffix; rather, all combinations of its values are stripped:
397<div class="verbatim"><pre>
398 &gt;&gt;&gt; ' spacious '.rstrip()
399 ' spacious'
400 &gt;&gt;&gt; 'mississippi'.rstrip('ipz')
401 'mississ'
402</pre></div>
403
404<span class="versionnote">Changed in version 2.2.2:
405Support for the <var>chars</var> argument.</span>
406
407</dl>
408
409<P>
410<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
411 <td><nobr><b><tt id='l2h-202' xml:id='l2h-202' class="method">split</tt></b>(</nobr></td>
412 <td><var></var><big>[</big><var>sep </var><big>[</big><var>,maxsplit</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
413<dd>
414Return a list of the words in the string, using <var>sep</var> as the
415delimiter string. If <var>maxsplit</var> is given, at most <var>maxsplit</var>
416splits are done. (thus, the list will have at most <code><var>maxsplit</var>+1</code>
417elements). If <var>maxsplit</var> is not specified, then there
418is no limit on the number of splits (all possible splits are made).
419Consecutive delimiters are not grouped together and are
420deemed to delimit empty strings (for example, "<tt class="samp">'1,,2'.split(',')</tt>"returns "<tt class="samp">['1', '', '2']</tt>"). The <var>sep</var> argument may consist of
421multiple characters (for example, "<tt class="samp">'1, 2, 3'.split(', ')</tt>" returns
422"<tt class="samp">['1', '2', '3']</tt>"). Splitting an empty string with a specified
423separator returns "<tt class="samp">['']</tt>".
424
425<P>
426If <var>sep</var> is not specified or is <code>None</code>, a different splitting
427algorithm is applied. First, whitespace characters (spaces, tabs,
428newlines, returns, and formfeeds) are stripped from both ends. Then,
429words are separated by arbitrary length strings of whitespace
430characters. Consecutive whitespace delimiters are treated as a single
431delimiter ("<tt class="samp">'1 2 3'.split()</tt>" returns "<tt class="samp">['1', '2', '3']</tt>").
432Splitting an empty string or a string consisting of just whitespace
433returns an empty list.
434</dl>
435
436<P>
437<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
438 <td><nobr><b><tt id='l2h-203' xml:id='l2h-203' class="method">splitlines</tt></b>(</nobr></td>
439 <td><var></var><big>[</big><var>keepends</var><big>]</big><var></var>)</td></tr></table></dt>
440<dd>
441Return a list of the lines in the string, breaking at line
442boundaries. Line breaks are not included in the resulting list unless
443<var>keepends</var> is given and true.
444</dl>
445
446<P>
447<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
448 <td><nobr><b><tt id='l2h-204' xml:id='l2h-204' class="method">startswith</tt></b>(</nobr></td>
449 <td><var>prefix</var><big>[</big><var>,
450 start</var><big>[</big><var>, end</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
451<dd>
452Return <code>True</code> if string starts with the <var>prefix</var>, otherwise
453return <code>False</code>. With optional <var>start</var>, test string beginning at
454that position. With optional <var>end</var>, stop comparing string at that
455position.
456</dl>
457
458<P>
459<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
460 <td><nobr><b><tt id='l2h-205' xml:id='l2h-205' class="method">strip</tt></b>(</nobr></td>
461 <td><var></var><big>[</big><var>chars</var><big>]</big><var></var>)</td></tr></table></dt>
462<dd>
463Return a copy of the string with the leading and trailing characters
464removed. The <var>chars</var> argument is a string specifying the set of
465characters to be removed. If omitted or <code>None</code>, the <var>chars</var>
466argument defaults to removing whitespace. The <var>chars</var> argument is not
467a prefix or suffix; rather, all combinations of its values are stripped:
468<div class="verbatim"><pre>
469 &gt;&gt;&gt; ' spacious '.strip()
470 'spacious'
471 &gt;&gt;&gt; 'www.example.com'.strip('cmowz.')
472 'example'
473</pre></div>
474
475<span class="versionnote">Changed in version 2.2.2:
476Support for the <var>chars</var> argument.</span>
477
478</dl>
479
480<P>
481<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
482 <td><nobr><b><tt id='l2h-206' xml:id='l2h-206' class="method">swapcase</tt></b>(</nobr></td>
483 <td><var></var>)</td></tr></table></dt>
484<dd>
485Return a copy of the string with uppercase characters converted to
486lowercase and vice versa.
487
488<P>
489For 8-bit strings, this method is locale-dependent.
490</dl>
491
492<P>
493<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
494 <td><nobr><b><tt id='l2h-207' xml:id='l2h-207' class="method">title</tt></b>(</nobr></td>
495 <td><var></var>)</td></tr></table></dt>
496<dd>
497Return a titlecased version of the string: words start with uppercase
498characters, all remaining cased characters are lowercase.
499
500<P>
501For 8-bit strings, this method is locale-dependent.
502</dl>
503
504<P>
505<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
506 <td><nobr><b><tt id='l2h-208' xml:id='l2h-208' class="method">translate</tt></b>(</nobr></td>
507 <td><var>table</var><big>[</big><var>, deletechars</var><big>]</big><var></var>)</td></tr></table></dt>
508<dd>
509Return a copy of the string where all characters occurring in the
510optional argument <var>deletechars</var> are removed, and the remaining
511characters have been mapped through the given translation table, which
512must be a string of length 256.
513
514<P>
515For Unicode objects, the <tt class="method">translate()</tt> method does not
516accept the optional <var>deletechars</var> argument. Instead, it
517returns a copy of the <var>s</var> where all characters have been mapped
518through the given translation table which must be a mapping of
519Unicode ordinals to Unicode ordinals, Unicode strings or <code>None</code>.
520Unmapped characters are left untouched. Characters mapped to <code>None</code>
521are deleted. Note, a more flexible approach is to create a custom
522character mapping codec using the <tt class="module"><a href="module-codecs.html">codecs</a></tt> module (see
523<tt class="module">encodings.cp1251</tt> for an example).
524</dl>
525
526<P>
527<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
528 <td><nobr><b><tt id='l2h-209' xml:id='l2h-209' class="method">upper</tt></b>(</nobr></td>
529 <td><var></var>)</td></tr></table></dt>
530<dd>
531Return a copy of the string converted to uppercase.
532
533<P>
534For 8-bit strings, this method is locale-dependent.
535</dl>
536
537<P>
538<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
539 <td><nobr><b><tt id='l2h-210' xml:id='l2h-210' class="method">zfill</tt></b>(</nobr></td>
540 <td><var>width</var>)</td></tr></table></dt>
541<dd>
542Return the numeric string left filled with zeros in a string
543of length <var>width</var>. The original string is returned if
544<var>width</var> is less than <code>len(<var>s</var>)</code>.
545
546<span class="versionnote">New in version 2.2.2.</span>
547
548</dl>
549
550<P>
551
552<DIV CLASS="navigation">
553<div class='online-navigation'>
554<p></p><hr />
555<table align="center" width="100%" cellpadding="0" cellspacing="2">
556<tr>
557<td class='online-navigation'><a rel="prev" title="2.3.6 Sequence Types "
558 href="typesseq.html"><img src='../icons/previous.png'
559 border='0' height='32' alt='Previous Page' width='32' /></A></td>
560<td class='online-navigation'><a rel="parent" title="2.3.6 Sequence Types "
561 href="typesseq.html"><img src='../icons/up.png'
562 border='0' height='32' alt='Up One Level' width='32' /></A></td>
563<td class='online-navigation'><a rel="next" title="2.3.6.2 String Formatting Operations"
564 href="typesseq-strings.html"><img src='../icons/next.png'
565 border='0' height='32' alt='Next Page' width='32' /></A></td>
566<td align="center" width="100%">Python Library Reference</td>
567<td class='online-navigation'><a rel="contents" title="Table of Contents"
568 href="contents.html"><img src='../icons/contents.png'
569 border='0' height='32' alt='Contents' width='32' /></A></td>
570<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
571 border='0' height='32' alt='Module Index' width='32' /></a></td>
572<td class='online-navigation'><a rel="index" title="Index"
573 href="genindex.html"><img src='../icons/index.png'
574 border='0' height='32' alt='Index' width='32' /></A></td>
575</tr></table>
576<div class='online-navigation'>
577<b class="navlabel">Previous:</b>
578<a class="sectref" rel="prev" href="typesseq.html">2.3.6 Sequence Types </A>
579<b class="navlabel">Up:</b>
580<a class="sectref" rel="parent" href="typesseq.html">2.3.6 Sequence Types </A>
581<b class="navlabel">Next:</b>
582<a class="sectref" rel="next" href="typesseq-strings.html">2.3.6.2 String Formatting Operations</A>
583</div>
584</div>
585<hr />
586<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
587</DIV>
588<!--End of Navigation Panel-->
589<ADDRESS>
590See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
591</ADDRESS>
592</BODY>
593</HTML>