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

📄 index.lxp@lxpwrap=x719_252ehtm.htm

📁 GUI Programming with Python
💻 HTM
字号:
    <table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td>    <div align="center" id="bldcontent">      <a href="../default.htm"><img src="../images/opendocs.png" width="63" height="76" border="0"></a>      <br>      <div class="symbol">Your OpenSource Publisher&#153;</div>    </div>      </td></tr></table>    <div align="center" class="author">      	<a href="../products.lxp">Products</a>	&nbsp;|&nbsp;	<a href="../wheretobuy.lxp">Where to buy</a>	&nbsp;|&nbsp;	<a href="../bookstore.lxp">Retailers</a>	&nbsp;|&nbsp;	<a href="../faq.lxp">FAQ</a>	&nbsp;|&nbsp;        <a href="../writeforus.lxp">Write for Us.</a>        &nbsp;|&nbsp;        <a href="#contact">Contact Us.</a>  </div>    <table border="0" cellspacing="3" cellpadding="0" width="100%"><tr><td width="100%">      <div class="content">        <table border="0" cellspacing="2" cellpadding="0" width="100%"><tr><td width="100%">          <div align="center"><H4 CLASS="AUTHOR"><A NAME="AEN5">Boudewijn Rempt</A><br><a href="../../https@secure.linuxports.com/opendocs/default.htm"><img src=odpyqt125.png></a><br>ISBN: 0-97003300-4-4<br><a href="../../https@secure.linuxports.com/opendocs/default.htm">Available from bookstores everywhere or you can order it here.</a><p>You can download the source files for the book <a href="pyqtsrc.tgz">(code / eps) here.</a><hr></div>                    <HTML><HEAD><TITLE>The Rules</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.72"><LINKREL="HOME"TITLE="GUI Programming with Python: QT Edition"HREF="book1.htm"><LINKREL="UP"TITLE="Introduction to Python"HREF="c653.htm"><LINKREL="PREVIOUS"TITLE="Introduction to Python"HREF="c653.htm"><LINKREL="NEXT"TITLE="Constructions"HREF="x823.htm"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GUI Programming with Python: QT Edition</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><A accesskey="P" href="index.lxp@lxpwrap=c653_252ehtm.htm">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 4. Introduction to Python</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><A accesskey="N" href="index.lxp@lxpwrap=x823_252ehtm.htm">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1">The Rules</A></H1><P>For a full treatment of the rules of      Python, see the Python Language Reference, which is available      online with BlackAdder and Python. This section will in a series      of short statements enumerate what makes Python Python.</P><DIVCLASS="SECT2"><H2CLASS="SECT2">Objects and references</A></H2><P>Before Python 2.2, not all types were        classes, but now they are.</P><P>Moore's law has made type declarations        obsolete (with thanks to Paul Prescod).</P><P>An object has a type (which you can        query with <TTCLASS="FUNCTION">type()</TT>). A reference does not        have a type. You can use the same name to refer to two objects        in succession, but the first reference disappears as soon as        you've made the second.</P><P>Objects disappear once the last        reference has gone (except if the reference is an explicit        weak reference). You can destroy a reference with        <TTCLASS="FUNCTION">del</TT> &#8212; from that moment on, the name        doesn't exist anymore. If you set the reference to        <TTCLASS="VARNAME">None</TT>, the link to the object disappears,        but the reference remains in existence.</P><PRECLASS="SCREEN">&#62;&#62;&#62; a="aaa"&#62;&#62;&#62; print aaaa&#62;&#62;&#62; del a&#62;&#62;&#62; print aTraceback (most recent call last):  File "&#60;stdin&#62;", line 1, in ?NameError: name 'a' is not defined&#62;&#62;&#62; a="aaa"&#62;&#62;&#62; print aaaa&#62;&#62;&#62; a=None&#62;&#62;&#62; print aNone&#62;&#62;&#62;      </PRE><P>Functions and classes are both also        objects.</P><P>Every object has one identity, which        you can retrieve with <TTCLASS="FUNCTION">id()</TT>:</P><PRECLASS="SCREEN">&#62;&#62;&#62; a=A()&#62;&#62;&#62; id(a)135121324          </PRE><P>Some types are callable (i.e., put on a        line with an argument list between ()) and can return a value.        Callable types include classes, methods in clasess, functions        and objects that implement the special method        <TTCLASS="FUNCTION">__call__</TT>.          </P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">Formatting</A></H2><P>A block is first marked by a colon at        the end of the previous line, and is indented. The block ends        at the next dedent. (You should indent with four spaces, and        not use tabs.)</P><P>Whatever is typed between brackets is        considered to be on one line. Dictionaries are delimited with        curlies {}, lists are delimited with brackets [] and tuples        (and lists of arguments to functions) are delimited with        ().</P><P>A classname should start with a capital        letter; variable and function names should begin with a        lowercase letter.</P><P>Only alphabetic characters (a-z, A-Z),        digits (0-9) and the underscore (_) are valid in variable        names, but a variable name should not start with a        digit.</P><P>Names that start with one underscore (_)        are a bit private (not imported with <TTCLASS="USERINPUT"><B>from module          import *</B></TT>); names that start with two underscores        (__) are very private in scope (not visible with        <TTCLASS="USERINPUT"><B>dir(object)</B></TT>); names that start and end        with two underscores are system-defined.</P><PRECLASS="SCREEN">Python 2.1.1 (#1, Aug 11 2001, 20:14:53)[GCC 2.95.2 19991024 (release)] on linux2Type "copyright", "credits" or "license" for more information.&#62;&#62;&#62; class A:...     def __test():...             pass...&#62;&#62;&#62; dir(A)['_A__test', '__doc__', '__module__']&#62;&#62;&#62; a=A()&#62;&#62;&#62; dir (a)[]      </PRE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">Keywords</A></H2><P>The following keywords are reserved:      </P><PRECLASS="SCREEN">and       del       for       is        raiseassert    elif      from      lambda    returnbreak     else      global    not       tryclass     except    if        or        whilecontinue  exec      import    pass      yielddef       finally   in        print        </PRE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">Literals</A></H2><P>Strings can be enclosed in single (' or        ") or triple (''' or """") quotes. Triple-quoted strings can        span lines, the linebreaks are part of the string. If you        prefix the string literal with u, it becomes a Unicode        string.</P><P>Numbers can be integers, long integers,        floating point, and imaginary. If you divide integers or long        integers, you will not get a float, but the integer before the        decimal symbol (unless you <TTCLASS="LITERAL">import division from          future</TT> in Python 2.2).</P><P>Python has the following operators:</P><PRECLASS="SCREEN">+       &#8212;       *       **      /       %&#60;&#60;      &#62;&#62;      &#38;       |       ^       ~&#60;       &#62;       &#60;=      &#62;=      ==      !=      &#60;&#62;      </PRE><P>The comparison operators        <TTCLASS="FUNCTION">&#60;&#62;</TT> and <TTCLASS="FUNCTION">!=</TT> are        alternate spellings of the same operator.        <TTCLASS="FUNCTION">!=</TT> is the preferred spelling;        <TTCLASS="FUNCTION">&#60;&#62;</TT> is obsolescent.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">Methods and functions</A></H2><P>Functions are callable objects that        return a value (if a function doesn't explicitly return a        value, it retuns <TTCLASS="VARNAME">None</TT>). Methods are the        same, but part of a class. A method's argument list always has        <TTCLASS="VARNAME">self</TT> (which refers to the class instance)        as its first argument.</P><P>A function can be called with positional        arguments, or named arguments. When mixed, positional        arguments come first.      </P><P>A variable number of positional        arguments is indicated by <TTCLASS="VARNAME">*args</TT>, and a        variable number of named arguments is indicated by        <TTCLASS="VARNAME">**args</TT>. You can access        <TTCLASS="VARNAME">*args</TT> as a tuple in your function, and        <TTCLASS="VARNAME">**args</TT> as a dictionary in your        function.</P><PRECLASS="SCREEN">&#62;&#62;&#62; def f(a):...     print a...&#62;&#62;&#62; def ff(a, b):...     print a, b...&#62;&#62;&#62; def fff(*args):...     print args...&#62;&#62;&#62; def ffff(**args):...     print args...&#62;&#62;&#62; f(1)1&#62;&#62;&#62; ff(1, b=2)1 2&#62;&#62;&#62; fff(1,2,3)(1, 2, 3)&#62;&#62;&#62; ffff(a=1,b=2,c=3){'b': 2, 'c': 3, 'a': 1}&#62;&#62;&#62;</PRE></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2">High level datatypes</A></H2><P>Python has three very high level        datatypes: tuples, lists and dictionaries.</P><P>A tuple is any combination of unique        objects. You can't change the composition of items in a tuple        (i.e. substitute another object), although the objects        themselves can be changed.</P><PRECLASS="SCREEN">&#62;&#62;&#62; t=("a","b","c")&#62;&#62;&#62; t('a', 'b', 'c')&#62;&#62;&#62; t[2]="d"Traceback (most recent call last):  File "&#60;stdin&#62;", line 1, in ?TypeError: object doesn't support item assignment&#62;&#62;&#62;      </PRE><P>A list is a list of objects. You can        change which objects are in a list, adding and deleting items        to your heart's delight.</P><PRECLASS="SCREEN">&#62;&#62;&#62; l=["a", "b", "c"]&#62;&#62;&#62; l[2]="d"&#62;&#62;&#62; l['a', 'b', 'd']&#62;&#62;&#62;      </PRE><P>A dictiony is a keyed list. Keys, which        must be unchangeable (i.e. not lists) point to values. One        key, one value. There can be no duplicate keys in a        dictionary.</P><PRECLASS="SCREEN">&#62;&#62;&#62; d={"a": "aaa", "b": "bbb", "c": "ccc"}&#62;&#62;&#62; d{'b': 'bbb', 'c': 'ccc', 'a': 'aaa'}&#62;&#62;&#62; d[2]Traceback (most recent call last):  File "&#60;stdin&#62;", line 1, in ?KeyError: 2&#62;&#62;&#62; d["b"]'bbb'&#62;&#62;&#62; d["b"]="ddd"&#62;&#62;&#62; d{'b': 'ddd', 'c': 'ccc', 'a': 'aaa'}&#62;&#62;&#62;      </PRE></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><A accesskey="P" href="index.lxp@lxpwrap=c653_252ehtm.htm">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="H" href="index.lxp@lxpwrap=book1_252ehtm">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><A accesskey="N" href="index.lxp@lxpwrap=x823_252ehtm.htm">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Introduction to Python</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><A accesskey="U" href="index.lxp@lxpwrap=c653_252ehtm.htm">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Constructions</TD></TR></TABLE></DIV></BODY></HTML>      </td>      </tr>      </table>      </td>    </tr>  </table>      

⌨️ 快捷键说明

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