PageRenderTime 26ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/python/library/strings.html

https://bitbucket.org/thncr/manuals
HTML | 238 lines | 224 code | 14 blank | 0 comment | 0 complexity | 295e933fecc223a83fa4ab78a65d9534 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>7. String Services &mdash; Python v2.7.3 documentation</title>
  7. <link rel="stylesheet" href="../_static/default.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '2.7.3',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../_static/jquery.js"></script>
  19. <script type="text/javascript" src="../_static/underscore.js"></script>
  20. <script type="text/javascript" src="../_static/doctools.js"></script>
  21. <script type="text/javascript" src="../_static/sidebar.js"></script>
  22. <link rel="search" type="application/opensearchdescription+xml"
  23. title="Search within Python v2.7.3 documentation"
  24. href="../_static/opensearch.xml"/>
  25. <link rel="author" title="About these documents" href="../about.html" />
  26. <link rel="copyright" title="Copyright" href="../copyright.html" />
  27. <link rel="top" title="Python v2.7.3 documentation" href="../index.html" />
  28. <link rel="up" title="The Python Standard Library" href="index.html" />
  29. <link rel="next" title="7.1. string β€” Common string operations" href="string.html" />
  30. <link rel="prev" title="6. Built-in Exceptions" href="exceptions.html" />
  31. <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
  32. <script type="text/javascript" src="../_static/copybutton.js"></script>
  33. <script type="text/javascript" src="../_static/version_switch.js"></script>
  34. </head>
  35. <body>
  36. <div class="related">
  37. <h3>Navigation</h3>
  38. <ul>
  39. <li class="right" style="margin-right: 10px">
  40. <a href="../genindex.html" title="General Index"
  41. accesskey="I">index</a></li>
  42. <li class="right" >
  43. <a href="../py-modindex.html" title="Python Module Index"
  44. >modules</a> |</li>
  45. <li class="right" >
  46. <a href="string.html" title="7.1. string β€” Common string operations"
  47. accesskey="N">next</a> |</li>
  48. <li class="right" >
  49. <a href="exceptions.html" title="6. Built-in Exceptions"
  50. accesskey="P">previous</a> |</li>
  51. <li><img src="../_static/py.png" alt=""
  52. style="vertical-align: middle; margin-top: -1px"/></li>
  53. <li><a href="http://www.python.org/">Python</a> &raquo;</li>
  54. <li>
  55. <span class="version_switcher_placeholder">2.7.3</span>
  56. <a href="../index.html">Documentation</a> &raquo;
  57. </li>
  58. <li><a href="index.html" accesskey="U">The Python Standard Library</a> &raquo;</li>
  59. </ul>
  60. </div>
  61. <div class="document">
  62. <div class="documentwrapper">
  63. <div class="bodywrapper">
  64. <div class="body">
  65. <div class="section" id="string-services">
  66. <span id="stringservices"></span><h1>7. String Services<a class="headerlink" href="#string-services" title="Permalink to this headline">ΒΆ</a></h1>
  67. <p>The modules described in this chapter provide a wide range of string
  68. manipulation operations.</p>
  69. <p>In addition, Python&#8217;s built-in string classes support the sequence type
  70. methods described in the <a class="reference internal" href="stdtypes.html#typesseq"><em>Sequence Types &#8212; str, unicode, list, tuple, bytearray, buffer, xrange</em></a> section, and also the
  71. string-specific methods described in the <a class="reference internal" href="stdtypes.html#string-methods"><em>String Methods</em></a> section.
  72. To output formatted strings use template strings or the <tt class="docutils literal"><span class="pre">%</span></tt> operator
  73. described in the <a class="reference internal" href="stdtypes.html#string-formatting"><em>String Formatting Operations</em></a> section. Also, see the
  74. <a class="reference internal" href="re.html#module-re" title="re: Regular expression operations."><tt class="xref py py-mod docutils literal"><span class="pre">re</span></tt></a> module for string functions based on regular expressions.</p>
  75. <div class="toctree-wrapper compound">
  76. <ul>
  77. <li class="toctree-l1"><a class="reference internal" href="string.html">7.1. <tt class="docutils literal"><span class="pre">string</span></tt> &#8212; Common string operations</a><ul>
  78. <li class="toctree-l2"><a class="reference internal" href="string.html#string-constants">7.1.1. String constants</a></li>
  79. <li class="toctree-l2"><a class="reference internal" href="string.html#string-formatting">7.1.2. String Formatting</a></li>
  80. <li class="toctree-l2"><a class="reference internal" href="string.html#format-string-syntax">7.1.3. Format String Syntax</a><ul>
  81. <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>
  82. <li class="toctree-l3"><a class="reference internal" href="string.html#format-examples">7.1.3.2. Format examples</a></li>
  83. </ul>
  84. </li>
  85. <li class="toctree-l2"><a class="reference internal" href="string.html#template-strings">7.1.4. Template strings</a></li>
  86. <li class="toctree-l2"><a class="reference internal" href="string.html#string-functions">7.1.5. String functions</a></li>
  87. <li class="toctree-l2"><a class="reference internal" href="string.html#deprecated-string-functions">7.1.6. Deprecated string functions</a></li>
  88. </ul>
  89. </li>
  90. <li class="toctree-l1"><a class="reference internal" href="re.html">7.2. <tt class="docutils literal"><span class="pre">re</span></tt> &#8212; Regular expression operations</a><ul>
  91. <li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-syntax">7.2.1. Regular Expression Syntax</a></li>
  92. <li class="toctree-l2"><a class="reference internal" href="re.html#module-contents">7.2.2. Module Contents</a></li>
  93. <li class="toctree-l2"><a class="reference internal" href="re.html#regular-expression-objects">7.2.3. Regular Expression Objects</a></li>
  94. <li class="toctree-l2"><a class="reference internal" href="re.html#match-objects">7.2.4. Match Objects</a></li>
  95. <li class="toctree-l2"><a class="reference internal" href="re.html#examples">7.2.5. Examples</a><ul>
  96. <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>
  97. <li class="toctree-l3"><a class="reference internal" href="re.html#simulating-scanf">7.2.5.2. Simulating scanf()</a></li>
  98. <li class="toctree-l3"><a class="reference internal" href="re.html#search-vs-match">7.2.5.3. search() vs. match()</a></li>
  99. <li class="toctree-l3"><a class="reference internal" href="re.html#making-a-phonebook">7.2.5.4. Making a Phonebook</a></li>
  100. <li class="toctree-l3"><a class="reference internal" href="re.html#text-munging">7.2.5.5. Text Munging</a></li>
  101. <li class="toctree-l3"><a class="reference internal" href="re.html#finding-all-adverbs">7.2.5.6. Finding all Adverbs</a></li>
  102. <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>
  103. <li class="toctree-l3"><a class="reference internal" href="re.html#raw-string-notation">7.2.5.8. Raw String Notation</a></li>
  104. </ul>
  105. </li>
  106. </ul>
  107. </li>
  108. <li class="toctree-l1"><a class="reference internal" href="struct.html">7.3. <tt class="docutils literal"><span class="pre">struct</span></tt> &#8212; Interpret strings as packed binary data</a><ul>
  109. <li class="toctree-l2"><a class="reference internal" href="struct.html#functions-and-exceptions">7.3.1. Functions and Exceptions</a></li>
  110. <li class="toctree-l2"><a class="reference internal" href="struct.html#format-strings">7.3.2. Format Strings</a><ul>
  111. <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>
  112. <li class="toctree-l3"><a class="reference internal" href="struct.html#format-characters">7.3.2.2. Format Characters</a></li>
  113. <li class="toctree-l3"><a class="reference internal" href="struct.html#examples">7.3.2.3. Examples</a></li>
  114. </ul>
  115. </li>
  116. <li class="toctree-l2"><a class="reference internal" href="struct.html#classes">7.3.3. Classes</a></li>
  117. </ul>
  118. </li>
  119. <li class="toctree-l1"><a class="reference internal" href="difflib.html">7.4. <tt class="docutils literal"><span class="pre">difflib</span></tt> &#8212; Helpers for computing deltas</a><ul>
  120. <li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-objects">7.4.1. SequenceMatcher Objects</a></li>
  121. <li class="toctree-l2"><a class="reference internal" href="difflib.html#sequencematcher-examples">7.4.2. SequenceMatcher Examples</a></li>
  122. <li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-objects">7.4.3. Differ Objects</a></li>
  123. <li class="toctree-l2"><a class="reference internal" href="difflib.html#differ-example">7.4.4. Differ Example</a></li>
  124. <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>
  125. </ul>
  126. </li>
  127. <li class="toctree-l1"><a class="reference internal" href="stringio.html">7.5. <tt class="docutils literal"><span class="pre">StringIO</span></tt> &#8212; Read and write strings as files</a></li>
  128. <li class="toctree-l1"><a class="reference internal" href="stringio.html#module-cStringIO">7.6. <tt class="docutils literal"><span class="pre">cStringIO</span></tt> &#8212; Faster version of <tt class="docutils literal"><span class="pre">StringIO</span></tt></a></li>
  129. <li class="toctree-l1"><a class="reference internal" href="textwrap.html">7.7. <tt class="docutils literal"><span class="pre">textwrap</span></tt> &#8212; Text wrapping and filling</a></li>
  130. <li class="toctree-l1"><a class="reference internal" href="codecs.html">7.8. <tt class="docutils literal"><span class="pre">codecs</span></tt> &#8212; Codec registry and base classes</a><ul>
  131. <li class="toctree-l2"><a class="reference internal" href="codecs.html#codec-base-classes">7.8.1. Codec Base Classes</a><ul>
  132. <li class="toctree-l3"><a class="reference internal" href="codecs.html#codec-objects">7.8.1.1. Codec Objects</a></li>
  133. <li class="toctree-l3"><a class="reference internal" href="codecs.html#incrementalencoder-objects">7.8.1.2. IncrementalEncoder Objects</a></li>
  134. <li class="toctree-l3"><a class="reference internal" href="codecs.html#incrementaldecoder-objects">7.8.1.3. IncrementalDecoder Objects</a></li>
  135. <li class="toctree-l3"><a class="reference internal" href="codecs.html#streamwriter-objects">7.8.1.4. StreamWriter Objects</a></li>
  136. <li class="toctree-l3"><a class="reference internal" href="codecs.html#streamreader-objects">7.8.1.5. StreamReader Objects</a></li>
  137. <li class="toctree-l3"><a class="reference internal" href="codecs.html#streamreaderwriter-objects">7.8.1.6. StreamReaderWriter Objects</a></li>
  138. <li class="toctree-l3"><a class="reference internal" href="codecs.html#streamrecoder-objects">7.8.1.7. StreamRecoder Objects</a></li>
  139. </ul>
  140. </li>
  141. <li class="toctree-l2"><a class="reference internal" href="codecs.html#encodings-and-unicode">7.8.2. Encodings and Unicode</a></li>
  142. <li class="toctree-l2"><a class="reference internal" href="codecs.html#standard-encodings">7.8.3. Standard Encodings</a></li>
  143. <li class="toctree-l2"><a class="reference internal" href="codecs.html#module-encodings.idna">7.8.4. <tt class="docutils literal"><span class="pre">encodings.idna</span></tt> &#8212; Internationalized Domain Names in Applications</a></li>
  144. <li class="toctree-l2"><a class="reference internal" href="codecs.html#module-encodings.utf_8_sig">7.8.5. <tt class="docutils literal"><span class="pre">encodings.utf_8_sig</span></tt> &#8212; UTF-8 codec with BOM signature</a></li>
  145. </ul>
  146. </li>
  147. <li class="toctree-l1"><a class="reference internal" href="unicodedata.html">7.9. <tt class="docutils literal"><span class="pre">unicodedata</span></tt> &#8212; Unicode Database</a></li>
  148. <li class="toctree-l1"><a class="reference internal" href="stringprep.html">7.10. <tt class="docutils literal"><span class="pre">stringprep</span></tt> &#8212; Internet String Preparation</a></li>
  149. <li class="toctree-l1"><a class="reference internal" href="fpformat.html">7.11. <tt class="docutils literal"><span class="pre">fpformat</span></tt> &#8212; Floating point conversions</a></li>
  150. </ul>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. <div class="sphinxsidebar">
  157. <div class="sphinxsidebarwrapper">
  158. <h4>Previous topic</h4>
  159. <p class="topless"><a href="exceptions.html"
  160. title="previous chapter">6. Built-in Exceptions</a></p>
  161. <h4>Next topic</h4>
  162. <p class="topless"><a href="string.html"
  163. title="next chapter">7.1. <tt class="docutils literal docutils literal docutils literal"><span class="pre">string</span></tt> &#8212; Common string operations</a></p>
  164. <h3>This Page</h3>
  165. <ul class="this-page-menu">
  166. <li><a href="../bugs.html">Report a Bug</a></li>
  167. <li><a href="../_sources/library/strings.txt"
  168. rel="nofollow">Show Source</a></li>
  169. </ul>
  170. <div id="searchbox" style="display: none">
  171. <h3>Quick search</h3>
  172. <form class="search" action="../search.html" method="get">
  173. <input type="text" name="q" size="18" />
  174. <input type="submit" value="Go" />
  175. <input type="hidden" name="check_keywords" value="yes" />
  176. <input type="hidden" name="area" value="default" />
  177. </form>
  178. <p class="searchtip" style="font-size: 90%">
  179. Enter search terms or a module, class or function name.
  180. </p>
  181. </div>
  182. <script type="text/javascript">$('#searchbox').show(0);</script>
  183. </div>
  184. </div>
  185. <div class="clearer"></div>
  186. </div>
  187. <div class="related">
  188. <h3>Navigation</h3>
  189. <ul>
  190. <li class="right" style="margin-right: 10px">
  191. <a href="../genindex.html" title="General Index"
  192. >index</a></li>
  193. <li class="right" >
  194. <a href="../py-modindex.html" title="Python Module Index"
  195. >modules</a> |</li>
  196. <li class="right" >
  197. <a href="string.html" title="7.1. string β€” Common string operations"
  198. >next</a> |</li>
  199. <li class="right" >
  200. <a href="exceptions.html" title="6. Built-in Exceptions"
  201. >previous</a> |</li>
  202. <li><img src="../_static/py.png" alt=""
  203. style="vertical-align: middle; margin-top: -1px"/></li>
  204. <li><a href="http://www.python.org/">Python</a> &raquo;</li>
  205. <li>
  206. <span class="version_switcher_placeholder">2.7.3</span>
  207. <a href="../index.html">Documentation</a> &raquo;
  208. </li>
  209. <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
  210. </ul>
  211. </div>
  212. <div class="footer">
  213. &copy; <a href="../copyright.html">Copyright</a> 1990-2013, Python Software Foundation.
  214. <br />
  215. The Python Software Foundation is a non-profit corporation.
  216. <a href="http://www.python.org/psf/donations/">Please donate.</a>
  217. <br />
  218. Last updated on Mar 20, 2013.
  219. <a href="../bugs.html">Found a bug</a>?
  220. <br />
  221. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
  222. </div>
  223. </body>
  224. </html>