⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-userstring.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>3.7 UserString -- Class wrapper for string objects</title>
<META NAME="description" CONTENT="3.7 UserString -- Class wrapper for string objects">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html">
<LINK REL="previous" href="module-UserList.html" tppabs="http://www.python.org/doc/current/lib/module-UserList.html">
<LINK REL="up" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">
<LINK REL="next" href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-UserList.html" tppabs="http://www.python.org/doc/current/lib/module-UserList.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-UserList.html" tppabs="http://www.python.org/doc/current/lib/module-UserList.html">3.6 UserList  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html">3.8 operator  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION005700000000000000000">
3.7 <tt class="module">UserString</tt> --
         Class wrapper for string objects</A>
</H1>

<P>


<P>
This module defines a class that acts as a wrapper around string
objects.  It is a useful base class for your own string-like classes,
which can inherit from them and override existing methods or add new
ones.  In this way one can add new behaviors to strings.

<P>
It should be noted that these classes are highly inefficient compared
to real string or Unicode objects; this is especially the case for
<tt class="class">MutableString</tt>.

<P>
The <tt class="module">UserString</tt> module defines the following classes:

<P>
<dl><dt><b><a name='l2h-323'><tt class='class'>UserString</tt></a></b> (<big>[</big><var>sequence</var><big>]</big>)
<dd>
Class that simulates a string or a Unicode string
object.  The instance's content is kept in a regular string or Unicode
string object, which is accessible via the <tt class="member">data</tt> attribute of
<tt class="class">UserString</tt> instances.  The instance's contents are initially
set to a copy of <var>sequence</var>.  <var>sequence</var> can be either a
regular Python string or Unicode string, an instance of
<tt class="class">UserString</tt> (or a subclass) or an arbitrary sequence which can
be converted into a string using the built-in <tt class="function">str()</tt> function.
</dl>

<P>
<dl><dt><b><a name='l2h-324'><tt class='class'>MutableString</tt></a></b> (<big>[</big><var>sequence</var><big>]</big>)
<dd>
This class is derived from the <tt class="class">UserString</tt> above and redefines
strings to be <i>mutable</i>.  Mutable strings can't be used as
dictionary keys, because dictionaries require <i>immutable</i> objects as
keys.  The main intention of this class is to serve as an educational
example for inheritance and necessity to remove (override) the
<tt class="method">__hash__()</tt> method in order to trap attempts to use a
mutable object as dictionary key, which would be otherwise very
error prone and hard to track down.
</dl>

<P>
In addition to supporting the methods and operations of string and
Unicode objects (see section <A href="string-methods.html#string-methods" tppabs="http://www.python.org/doc/current/lib/string-methods.html#string-methods">2.1.5</A>, ``String
Methods''), <tt class="class">UserString</tt> instances provide the following
attribute:

<P>
<dl><dt><b><a name='l2h-325'><tt class='member'>data</tt></a></b>
<dd>
A real Python string or Unicode object used to store the content of the
<tt class="class">UserString</tt> class.
</dl>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-UserList.html" tppabs="http://www.python.org/doc/current/lib/module-UserList.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-UserList.html" tppabs="http://www.python.org/doc/current/lib/module-UserList.html">3.6 UserList  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-operator.html" tppabs="http://www.python.org/doc/current/lib/module-operator.html">3.8 operator  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -