1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>7. String Services — Python 2.7.11 documentation</title>
11
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 2.7.11 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
33
<link rel="up" title="The Python Standard Library" href="index.html" />
34
<link rel="next" title="7.1. string — Common string operations" href="string.html" />
35
<link rel="prev" title="6. Built-in Exceptions" href="exceptions.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
<script type="text/javascript" src="../_static/copybutton.js"></script>
38
<script type="text/javascript" src="../_static/version_switch.js"></script>
43
<body role="document">
44
<div class="related" role="navigation" aria-label="related navigation">
47
<li class="right" style="margin-right: 10px">
48
<a href="../genindex.html" title="General Index"
49
accesskey="I">index</a></li>
51
<a href="../py-modindex.html" title="Python Module Index"
54
<a href="string.html" title="7.1. string — Common string operations"
55
accesskey="N">next</a> |</li>
57
<a href="exceptions.html" title="6. Built-in Exceptions"
58
accesskey="P">previous</a> |</li>
59
<li><img src="../_static/py.png" alt=""
60
style="vertical-align: middle; margin-top: -1px"/></li>
61
<li><a href="https://www.python.org/">Python</a> »</li>
63
<span class="version_switcher_placeholder">2.7.11</span>
64
<a href="../index.html">Documentation</a> »
67
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">The Python Standard Library</a> »</li>
71
<div class="document">
72
<div class="documentwrapper">
73
<div class="bodywrapper">
74
<div class="body" role="main">
76
<div class="section" id="string-services">
77
<span id="stringservices"></span><h1>7. String Services<a class="headerlink" href="#string-services" title="Permalink to this headline">¶</a></h1>
78
<p>The modules described in this chapter provide a wide range of string
79
manipulation operations.</p>
80
<p>In addition, Python’s built-in string classes support the sequence type
81
methods described in the <a class="reference internal" href="stdtypes.html#typesseq"><span>Sequence Types — str, unicode, list, tuple, bytearray, buffer, xrange</span></a> section, and also the
82
string-specific methods described in the <a class="reference internal" href="stdtypes.html#string-methods"><span>String Methods</span></a> section.
83
To output formatted strings use template strings or the <code class="docutils literal"><span class="pre">%</span></code> operator
84
described in the <a class="reference internal" href="stdtypes.html#string-formatting"><span>String Formatting Operations</span></a> section. Also, see the
85
<a class="reference internal" href="re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal"><span class="pre">re</span></code></a> module for string functions based on regular expressions.</p>
86
<div class="toctree-wrapper compound">
88
<li class="toctree-l1"><a class="reference internal" href="string.html">7.1. <code class="docutils literal"><span class="pre">string</span></code> — Common string operations</a><ul>
89
<li class="toctree-l2"><a class="reference internal" href="string.html#string-constants">7.1.1. String constants</a></li>
90
<li class="toctree-l2"><a class="reference internal" href="string.html#custom-string-formatting">7.1.2. Custom String Formatting</a></li>
91
<li class="toctree-l2"><a class="reference internal" href="string.html#format-string-syntax">7.1.3. Format String Syntax</a><ul>
92
<li class="toctree-l3"><a class="reference internal" href="string.html#format-specification-mini-language">7.1.3.1. Format Specification Mini-Language</a></li>
93
<li class="toctree-l3"><a class="reference internal" href="string.html#format-examples">7.1.3.2. Format examples</a></li>
96
<li class="toctree-l2"><a class="reference internal" href="string.html#template-strings">7.1.4. Template strings</a></li>
97
<li class="toctree-l2"><a class="reference internal" href="string.html#string-functions">7.1.5. String functions</a></li>
98
<li class="toctree-l2"><a class="reference internal" href="string.html#deprecated-string-functions">7.1.6. Deprecated string functions</a></li>
101
<li class="toctree-l1"><a class="reference internal" href="re.html">7.2. <code class="docutils literal"><span class="pre">re</span></code> — Regular expression operations</a><ul>
102
<li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-syntax">7.2.1. Regular Expression Syntax</a></li>
103
<li class="toctree-l2"><a class="reference internal" href="re.html#module-contents">7.2.2. Module Contents</a></li>
104
<li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-objects">7.2.3. Regular Expression Objects</a></li>
105
<li class="toctree-l2"><a class="reference internal" href="re.html#match-objects">7.2.4. Match Objects</a></li>
106
<li class="toctree-l2"><a class="reference internal" href="re.html#examples">7.2.5. Examples</a><ul>
107
<li class="toctree-l3"><a class="reference internal" href="re.html#checking-for-a-pair">7.2.5.1. Checking For a Pair</a></li>
108
<li class="toctree-l3"><a class="reference internal" href="re.html#simulating-scanf">7.2.5.2. Simulating scanf()</a></li>
109
<li class="toctree-l3"><a class="reference internal" href="re.html#search-vs-match">7.2.5.3. search() vs. match()</a></li>
110
<li class="toctree-l3"><a class="reference internal" href="re.html#making-a-phonebook">7.2.5.4. Making a Phonebook</a></li>
111
<li class="toctree-l3"><a class="reference internal" href="re.html#text-munging">7.2.5.5. Text Munging</a></li>
112
<li class="toctree-l3"><a class="reference internal" href="re.html#finding-all-adverbs">7.2.5.6. Finding all Adverbs</a></li>
113
<li class="toctree-l3"><a class="reference internal" href="re.html#finding-all-adverbs-and-their-positions">7.2.5.7. Finding all Adverbs and their Positions</a></li>
114
<li class="toctree-l3"><a class="reference internal" href="re.html#raw-string-notation">7.2.5.8. Raw String Notation</a></li>
119
<li class="toctree-l1"><a class="reference internal" href="struct.html">7.3. <code class="docutils literal"><span class="pre">struct</span></code> — Interpret strings as packed binary data</a><ul>
120
<li class="toctree-l2"><a class="reference internal" href="struct.html#functions-and-exceptions">7.3.1. Functions and Exceptions</a></li>
121
<li class="toctree-l2"><a class="reference internal" href="struct.html#format-strings">7.3.2. Format Strings</a><ul>
122
<li class="toctree-l3"><a class="reference internal" href="struct.html#byte-order-size-and-alignment">7.3.2.1. Byte Order, Size, and Alignment</a></li>
123
<li class="toctree-l3"><a class="reference internal" href="struct.html#format-characters">7.3.2.2. Format Characters</a></li>
124
<li class="toctree-l3"><a class="reference internal" href="struct.html#examples">7.3.2.3. Examples</a></li>
127
<li class="toctree-l2"><a class="reference internal" href="struct.html#classes">7.3.3. Classes</a></li>
130
<li class="toctree-l1"><a class="reference internal" href="difflib.html">7.4. <code class="docutils literal"><span class="pre">difflib</span></code> — Helpers for computing deltas</a><ul>
131
<li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-objects">7.4.1. SequenceMatcher Objects</a></li>
132
<li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-examples">7.4.2. SequenceMatcher Examples</a></li>
133
<li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-objects">7.4.3. Differ Objects</a></li>
134
<li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-example">7.4.4. Differ Example</a></li>
135
<li class="toctree-l2"><a class="reference internal" href="difflib.html#a-command-line-interface-to-difflib">7.4.5. A command-line interface to difflib</a></li>
138
<li class="toctree-l1"><a class="reference internal" href="stringio.html">7.5. <code class="docutils literal"><span class="pre">StringIO</span></code> — Read and write strings as files</a></li>
139
<li class="toctree-l1"><a class="reference internal" href="stringio.html#module-cStringIO">7.6. <code class="docutils literal"><span class="pre">cStringIO</span></code> — Faster version of <code class="docutils literal"><span class="pre">StringIO</span></code></a></li>
140
<li class="toctree-l1"><a class="reference internal" href="textwrap.html">7.7. <code class="docutils literal"><span class="pre">textwrap</span></code> — Text wrapping and filling</a></li>
141
<li class="toctree-l1"><a class="reference internal" href="codecs.html">7.8. <code class="docutils literal"><span class="pre">codecs</span></code> — Codec registry and base classes</a><ul>
142
<li class="toctree-l2"><a class="reference internal" href="codecs.html#codec-base-classes">7.8.1. Codec Base Classes</a><ul>
143
<li class="toctree-l3"><a class="reference internal" href="codecs.html#codec-objects">7.8.1.1. Codec Objects</a></li>
144
<li class="toctree-l3"><a class="reference internal" href="codecs.html#incrementalencoder-objects">7.8.1.2. IncrementalEncoder Objects</a></li>
145
<li class="toctree-l3"><a class="reference internal" href="codecs.html#incrementaldecoder-objects">7.8.1.3. IncrementalDecoder Objects</a></li>
146
<li class="toctree-l3"><a class="reference internal" href="codecs.html#streamwriter-objects">7.8.1.4. StreamWriter Objects</a></li>
147
<li class="toctree-l3"><a class="reference internal" href="codecs.html#streamreader-objects">7.8.1.5. StreamReader Objects</a></li>
148
<li class="toctree-l3"><a class="reference internal" href="codecs.html#streamreaderwriter-objects">7.8.1.6. StreamReaderWriter Objects</a></li>
149
<li class="toctree-l3"><a class="reference internal" href="codecs.html#streamrecoder-objects">7.8.1.7. StreamRecoder Objects</a></li>
152
<li class="toctree-l2"><a class="reference internal" href="codecs.html#encodings-and-unicode">7.8.2. Encodings and Unicode</a></li>
153
<li class="toctree-l2"><a class="reference internal" href="codecs.html#standard-encodings">7.8.3. Standard Encodings</a></li>
154
<li class="toctree-l2"><a class="reference internal" href="codecs.html#python-specific-encodings">7.8.4. Python Specific Encodings</a></li>
155
<li class="toctree-l2"><a class="reference internal" href="codecs.html#module-encodings.idna">7.8.5. <code class="docutils literal"><span class="pre">encodings.idna</span></code> — Internationalized Domain Names in Applications</a></li>
156
<li class="toctree-l2"><a class="reference internal" href="codecs.html#module-encodings.utf_8_sig">7.8.6. <code class="docutils literal"><span class="pre">encodings.utf_8_sig</span></code> — UTF-8 codec with BOM signature</a></li>
159
<li class="toctree-l1"><a class="reference internal" href="unicodedata.html">7.9. <code class="docutils literal"><span class="pre">unicodedata</span></code> — Unicode Database</a></li>
160
<li class="toctree-l1"><a class="reference internal" href="stringprep.html">7.10. <code class="docutils literal"><span class="pre">stringprep</span></code> — Internet String Preparation</a></li>
161
<li class="toctree-l1"><a class="reference internal" href="fpformat.html">7.11. <code class="docutils literal"><span class="pre">fpformat</span></code> — Floating point conversions</a></li>
170
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
171
<div class="sphinxsidebarwrapper">
172
<h4>Previous topic</h4>
173
<p class="topless"><a href="exceptions.html"
174
title="previous chapter">6. Built-in Exceptions</a></p>
176
<p class="topless"><a href="string.html"
177
title="next chapter">7.1. <code class="docutils literal"><span class="pre">string</span></code> — Common string operations</a></p>
179
<ul class="this-page-menu">
180
<li><a href="../bugs.html">Report a Bug</a></li>
181
<li><a href="../_sources/library/strings.txt"
182
rel="nofollow">Show Source</a></li>
185
<div id="searchbox" style="display: none" role="search">
186
<h3>Quick search</h3>
187
<form class="search" action="../search.html" method="get">
188
<input type="text" name="q" />
189
<input type="submit" value="Go" />
190
<input type="hidden" name="check_keywords" value="yes" />
191
<input type="hidden" name="area" value="default" />
193
<p class="searchtip" style="font-size: 90%">
194
Enter search terms or a module, class or function name.
197
<script type="text/javascript">$('#searchbox').show(0);</script>
200
<div class="clearer"></div>
202
<div class="related" role="navigation" aria-label="related navigation">
205
<li class="right" style="margin-right: 10px">
206
<a href="../genindex.html" title="General Index"
209
<a href="../py-modindex.html" title="Python Module Index"
212
<a href="string.html" title="7.1. string — Common string operations"
215
<a href="exceptions.html" title="6. Built-in Exceptions"
217
<li><img src="../_static/py.png" alt=""
218
style="vertical-align: middle; margin-top: -1px"/></li>
219
<li><a href="https://www.python.org/">Python</a> »</li>
221
<span class="version_switcher_placeholder">2.7.11</span>
222
<a href="../index.html">Documentation</a> »
225
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
229
© <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
231
The Python Software Foundation is a non-profit corporation.
232
<a href="https://www.python.org/psf/donations/">Please donate.</a>
234
Last updated on Feb 07, 2016.
235
<a href="../bugs.html">Found a bug</a>?
237
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
b'\\ No newline at end of file'