<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>砼砼&#039;s  Blog &#187; python</title>
	<atom:link href="http://tossp.com/cat/z7z8/safe/python-safe-z7z8/feed" rel="self" type="application/rss+xml" />
	<link>http://tossp.com</link>
	<description>砼&#60;-这个字读tong，男人是泥做的，女人是水做的，我是混凝土做的。</description>
	<lastBuildDate>Sun, 22 Apr 2012 01:59:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<atom:link rel='hub' href='http://tossp.com/?pushpress=hub'/>
		<item>
		<title>PyThon学习笔记(7章)</title>
		<link>http://tossp.com/python-study-notes-7.html</link>
		<comments>http://tossp.com/python-study-notes-7.html#comments</comments>
		<pubDate>Wed, 26 May 2010 16:57:29 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/?p=2140</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:45最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
映射和集合类型(chapter7)

<div class="clear"></div><a href="http://tossp.com/python-study-notes-7.html" title="PyThon学习笔记(7章)" rel="external" class="more-link">阅读全文-—共2421字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:45</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>映射和集合类型(chapter7)</h1>
<ol>
<li>
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表</li>
<li>
字典的创建和赋值</p>
<ol>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span> <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span>key: value<span style="color: black;">&#125;</span></div></div>
</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>key<span style="color: #66cc66;">,</span> value<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span>key<span style="color: #66cc66;">,</span> value<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div></div>
</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span>.<span style="color: black;">fromkeys</span><span style="color: black;">&#40;</span>sequence_keys<span style="color: #66cc66;">,</span> default_value<span style="color: black;">&#41;</span></div></div>
<p>创建一个key是sequence_keys中元素的字典, 所有的value都是default_value, 如果不指定default_value, 默认是None</li>
</ol>
</li>
<li>
使用</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span>.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>可以判断一个字典中是否有这个键, 该方法在后期python可能弃用, 推荐使用in和not in</li>
<li>
字典的键必须是可哈希的</li>
<li>
print中使用到字典的时候, 使用字符串格式化方式是非常优雅的</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dict1.<span style="color: black;">update</span><span style="color: black;">&#40;</span>dict2 | tuple_list<span style="color: black;">&#91;</span><span style="color: #66cc66;">,</span> **key<span style="color: #66cc66;">=</span>value<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div></div>
<ol>
<li>
将dict2字典更新到dict1中</li>
<li>
如果参数是一个元组列表, 将元组列表解析到dict1中(元组列表中每个元组必须有两个元素)</li>
<li>
可以在参数后面跟0—n个关键字参数, 以参数名: value的方式更新到dict1中</li>
</ol>
</li>
<li>
元素的删除</p>
<ol>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">del</span> <span style="color: #008000;">dict</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;key&quot;</span><span style="color: black;">&#93;</span></div></div>
<p>删除键是key的条目</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span>.<span style="color: black;">clear</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>清空字典内的内容</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">dict</span>.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span></div></div>
<p>删除键是key的条目并返回</li>
</ol>
</li>
<li>
映射类型操作符</p>
<ol>
<li>
标准类型操作符: &lt;, &gt;等比较操作符可以使用, 在比较过程中, 还是调用了字典的cmp方法, 但是, 字典的cmp方法中指示, 首先比较字典的长度, 然后比较键的大小, 最后比较值的大小</li>
<li>
字典查找操作: [], 成员关系操作: in, not in</li>
</ol>
</li>
<li>
dict工厂函数</p>
<ol>
<li>
接受不定关键字参数:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>a <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span> b <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">2</span><span style="color: #66cc66;">,</span> c <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span></div></div>
</li>
<li>
接受字典或关键字参数: 将原有的字典拷贝出来成为一个新的字典(这里使用的浅拷贝, 这里的浅拷贝得到的结果和使用copy函数得到的结果是一样的,但是, copy函数的效率更高)</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dict_instance.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>使用已有的字典拷贝一个字典(这里使用的也是浅拷贝)</li>
</ol>
</li>
<li>
系统内建函数</p>
<ol>
<li>
len(): 返回字典的key-value对的数目</li>
<li>
hash(): 这个函数不是为字典设计的, 但是它可以判断某个对象是否可以做一个字典的键, 将一个对象作为参数传递给hash(), 会返回这个对象的哈希值.  如果对象是不可哈希的, 会返回TypeError, 提示该对象是unhashable的</li>
<li>
sorted(dict):  返回dict的所有key排序后的列表</li>
</ol>
</li>
<li>
dict类型的内建方法</p>
<ol>
<li>
keys(): 返回字典的所有key的列表</li>
<li>
values(): 返回字典的所有value的列表</li>
<li>
items(): 返回字典的所有key-value的元组的列表</li>
<li>
get(key, default = None):  获取字典内key对应的值, 如果没有该key, 返回default指定的默认值</li>
<li>
setdefault(key, default=None): 如果字典中不存在key, 由dict[key]=default为其赋值</li>
<li>
iterkeys(), itervalues(), iteritems() 对应没有iter命名的方法, 这里使用了惰性赋值的迭代器, 节省内存</li>
</ol>
</li>
<li>
数字作为字典的键的时候, 只要值相同, 就代表相同的键, 比如, 1, 和1.0代表的就是相同的键</li>
<li>
键必须是可哈希的, 所有的不可变对象都是可哈希的, 可变对象如果在定义中定义了__hash__()方法, 那么就可以作为键</li>
<li>
如果元组中的值都是不可变类型的, 那么元组也可以作为字典的键</li>
<li>
集合sets有两种不同的类型, 可变集合set和不可变集合frozenset…可变集合也是不可哈希的…</li>
<li>
集合中不能有重复的元素, 如果有元素和已有元素重复, 就不会被插入.集合是无序的, 但是, 可以使用排序函数为它排序</li>
<li>
集合中可以使用的数学符号</li>
</ol>
<ol>
<li>
集合只能使用工厂函数set和frozenset创建</li>
<li>
访问集合中的数据使用循环, 或者使用成员关系操作符in, not in判断元素是否属于集合</li>
<li>
更新集合(只能是set, frozenset不能被更新)</p>
<ol>
<li>
add()  添加一个元素</li>
<li>
s.update()  接受一个序列类型的参数, 把该序列中有而集合中没有的元素添加到集合中</li>
<li>
s.remove()  从集合中移除一个元素</li>
</ol>
</li>
<li>
集合可用的标准类型操作符</p>
<ol>
<li>
成员关系: in, not in</li>
<li>
集合等价/不等价: ==, !=</li>
<li>
子集/超集: &lt;, &lt;=, &gt;, &gt;=</li>
</ol>
</li>
<li>
集合类型操作符(所有的集合类型)  集合互相操作的时候, 最后产生的集合是可变集合还是不可变集合取决于第一个参与操作的集合的类型</p>
<ol>
<li>
联合 |</li>
<li>
交集 &amp;</li>
<li>
差补/相对补集  &#8211;  A-B就返回属于A 但不属于B的元素集合</li>
<li>
对称差分   ^  A^B = A-B + B-A</li>
</ol>
</li>
<li>
可变集合特有的操作符</p>
<ol>
<li>
|=  相当于update方法, 并集赋值</li>
<li>
&amp;=  相当于intersection_update()方法, 交集赋值</li>
<li>
-=   相当于difference_update()方法, 差集赋值</li>
<li>
^=  相当于symmetric_difference_update()方法, 对称差分更新</li>
</ol>
</li>
<li>
集合类型的内部方法:</p>
<ol>
<li>
s.issubset(t)  判断s是不是t的子集</li>
<li>
s.issuperset(t)  判断s是不是t的超集</li>
<li>
s.union(t)   返回一个新集合, 该集合是s和t的并集</li>
<li>
s.intersection(t)  返回一个新集合, 该集合是s和t的交集</li>
<li>
s.difference(t)  返回一个新集合, 该集合是s的成员, 但不是t的成员, 即返回s不同于t的元素</li>
<li>
s.symmetric_defference(t)  返回所有s和t独有的(非共同拥有)元素集合</li>
<li>
s.copy()  返回一个s的浅拷贝, 效率比工厂要好</li>
</ol>
</li>
<li>
可变集合特有的方法: add, remove, discard, pop, clear, 这些接受对象的方法, 参数必须是可哈希的</li>
<li>
那些和操作符提供相同功能的函数, 有着更强的处理能力, 因为运算符两边的操作数必须都是集合, 然而函数可以接受任何的可迭代类型.</li>
</ol>
<hr /><h2>Comments</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html">2010 年 05 月 30 日</a>, <a href='http://zww.me' rel='external nofollow' class='url'>zwwooooo</a> writes: 沙发。。。</li><li><a href="http://tossp.com/python-study-notes-7.html">2010 年 06 月 02 日</a>, <a href='http://www.xiaozizai.com' rel='external nofollow' class='url'>Four eyes</a> writes: 真厉害 豆瓣就是这个语言写得</li></ul><hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(1, 2章)">PyThon学习笔记(1, 2章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

	
Python.exe 的解释器options:

	
–d   提供调试输出
	
–O   生成优化的字节码(生成.pyo文件)
	
–S  </li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li><li><a href="http://tossp.com/python-study-notes-3-chapters.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(3章)">PyThon学习笔记(3章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
Python基础(chapter3)

	
setence and syntax语句和语法

	
#为注释符号
	
n是标准行分隔符, 通常一个语句一行
	
反斜线表示下一行继续, 用来将单条语句放入多行…尽量使用括号代替
	
分号;表示将两个语句连接在一行中…不提倡
	
冒号:表示将代码块的头和体分开
	
语句(代码块)用缩进块方式体现: 同一个代码组的代码必须严格左对齐..由于不同的editor制表符宽度不一, 为了使代码跨平台, 推荐使用4个空格缩进
	
不同缩进深度分隔不同的代码块
	
python文件以模块的形式组织: 模块以磁盘文件的形式存在, 不应该让某个模块充斥的太大


	
赋值

	
赋值语句没有返回值,</li><li><a href="http://tossp.com/python-study-notes-chapter-5.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(5章)">PyThon学习笔记(5章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

数字(chapter5)

	
支持的数字类型: 整型, 长整型, 布尔型, 双精度浮点型, 十进制浮点型和复数
	
整型

	
布尔型  包含True和False两个值的整型
	
标准整数类型  0x表示十六进制,</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(4章)">PyThon学习笔记(4章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
python对象(chapter4)

	
python对象有三个特征: 身份和类型是只读的, 如果对象支持不支持更新操作, 那么值也就是只读的.

	
身份: 唯一的身份标识, 可以使用内建函数id()得到, 可以看作是对象的内存地址…
	
类型: 对象的类型决定该对象保存什么类型的值, 可以进行什么操作, 遵循什么规则.,</li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes-7.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PyThon学习笔记(6章)</title>
		<link>http://tossp.com/python-study-notes-chapter-6.html</link>
		<comments>http://tossp.com/python-study-notes-chapter-6.html#comments</comments>
		<pubDate>Mon, 24 May 2010 16:55:19 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/?p=2139</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:44最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
序列: 字符串, 列表和元组(chapter6)

<div class="clear"></div><a href="http://tossp.com/python-study-notes-chapter-6.html" title="PyThon学习笔记(6章)" rel="external" class="more-link">阅读全文-—共6313字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:44</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>序列: 字符串, 列表和元组(chapter6)</h1>
<ol>
<li>
对所有序列类型都适用的操作符(优先级从高到低, 不适用于复合类型的对象比较)</p>
<ol>
<li>
成员关系操作符: int, not in</li>
<li>
连接操作符: +</li>
<li>
重复操作符: *… sequence * int</li>
<li>
切片操作符: (利用子序列方式结合三种操作方式, 可以非常灵活的控制序列)</p>
<ol>
<li>
[], 索引取值</li>
<li>
[start : end], 索引范围取值</li>
<li>
[::step], 切片的步长</li>
<li>
切片操作符不会带来索引超出下标的异常</li>
</ol>
</li>
</ol>
</li>
<li>
list.extend(iterable): 把另外一个序列追加到list中.</li>
<li>
list.insert(index, object): 把一个元素object插入到list的index位置, 如果index是负数, 从后面向前数, 超过list下标后, 在末尾添加</li>
<li>
类型转换</p>
<ol>
<li>
list(iter)  把可迭代对象转换为列表</li>
<li>
str(obj)  把obj对象转换成字符串(对象的字符串表示法)</li>
<li>
unicode(obj)  把对象转换成Unicode字符串(使用默认编码), 使用u”汉字”可以得到其unicode编码</li>
<li>
basestring()  抽象工厂函数, 不能被实例化, 不能被调用, 仅作为str和unicode的父类</li>
<li>
tuple(iter)  把一个可迭代对象转换成元组对象</li>
<li>
enumerate(iterable)  生成由iterable每个元素的index值和item值组成的元组, 可以使用for key, value in enumerate的方式进行迭代</li>
<li>
max(iterable, key=None) | max(arg0, arg1, …, key=None) 返回iterable或arg0…中的最大值, 如果要指定key, 必须是一个可以传递给sort()方法的回调函数…..要使用key, 必须使用key=method_name的方式传参, key指定的函数接收的参数是迭代的当前元素, 在该函数中, 对元素进行处理, 返回一个对象, python会根据返回对象比较大小, 得到该结果最大的元素对应的list中的元素</li>
<li>
min同上面的max方法.  对于max和min方法, 如果是自定义类型, 又没有指定key, 那么默认是按照id(object)的结果计算的</li>
<li>
reversed(sequence)  返回逆序访问的迭代器</li>
<li>
sum(sequence, init=0)  返回sequence和可选参数init的总和, 等同于reduce(operator.add, sequence, init)</li>
<li>
sorted(iterable, func=None, key=None, reverse=False)  接受一个可迭代对象, 返回一个有序列表, 可选参数func, key, reverse含义和list.sort相同</li>
<li>
zip([item0, item1, …, itemn])  返回一个列表, [(item0, ), (item1, ), …, (itemn, )]</li>
<li>
sort(cmp=None, key=None, reverse=False)  将序列进行排序, cmp指定一个接受两个参数的回调函数, 该函数得到的两个参数是序列中的两个元素, 比较将按照cmp指定的回调函数进行, 返回数字类型的比较结果, , , key指定一个接受一个参数的回调函数句柄, 该参数就是迭代到的元素, 在比较之前, 将会根据这个回调函数对要比较的元素进行一次处理, 实际参与比较的是经过该回调函数处理之后的返回值.  reverse指示是否对比较结果进行逆序</li>
</ol>
</li>
<li>
利用已有功能函数定义动态参数的函数: method = lambda x, y: cmp(x + 10, y &#8211; 10), 调用时还是使用句柄加参数的方式: method(x, y)</li>
<li>
字符串: 如果先使用切片操作, 子串会被在内存中进行短时间的暂存, 可以通过id()得到值</li>
<li>
比较: 普通字符串按照ascii值比较, Unicode字符串按照unicode值比较.</li>
<li>
字符串切片, 下图是字符串切片的索引值, 如果开始或结束的索引值没有指定, 默认为0, 或-1. [::step]用于指定步长</li>
</ol>
<ol>
<li>
成员操作符: in, not in, 可以判断一个子串是否在字符串中存在…使用find(), index(), rfind(), rindex()可以获得子串在源中的位置</li>
<li>
string模块有一些预定义的字符串: ascii_letters, ascii_lowercase, ascii_uppercase, digits</li>
<li>
循环的改善: 如果循环的终止条件是不变的(一般都是不变的), 那么尽量不在循环终止条件中调用方法是一个好的习惯, 在大量数据的情况下(5 * 10^8数据), 改善的循环效率提升了4秒左右, 平均计算得到改善后循环每次效率提升约为7.154 * 10^-8s 也就是71.54 ns</li>
<li>
for-else方式的循环, else子句会在所有的元素都被循环完成之后执行, 如果break, 就不执行</li>
<li>
join可以用来连接字符串, 这样的效率是更高的, 因为+连接必须为每个字符串创建内存</li>
<li>
+连接字符串是运行时连接, “str1&#8243;”str2&#8243;的方式则是编译时连接字符串</li>
<li>
普通字符串和unicode字符串连接, 会把普通字符串转换成unicode字符串进行连接</li>
<li>
%格式化字符串的参数:</p>
<ol>
<li>
%c  转换成字符(ascii值, 或长度为一的字符串)</li>
<li>
%r  优先使用repr()函数进行字符串转换</li>
<li>
%s  优先使用str()函数进行字符串转换</li>
<li>
%d / %i  转成有符号的十进制数</li>
<li>
%u  转成无符号的十进制数  遇到负号添加-号</li>
<li>
%o  转成无符号八进制数  遇到负号添加-号</li>
<li>
%x / %X  转成无符号十六进制数(x|X的大小写决定转换后得到十六进制数中的字母的大小写)   遇到负数, 则转换得到的结果中添加一个-号</li>
<li>
%e / %E  转成科学计数法(e | E的大小写决定转换后得到的e的大小写)</li>
<li>
%f / %F  转成浮点数(小数部分自然截断)</li>
<li>
%%  输出%号</li>
</ol>
</li>
<li>
其他格式化操作符辅助指令(位于%和格式化标识的中间)</p>
<ol>
<li>
*  定义宽度或小数点精度”adfas%*dfasdf” % (5, 2.000000888)</li>
<li>
–  用于左对齐</li>
<li>
+  在正数前加+号</li>
<li>
(sp)  在正数前显示空格</li>
<li>
#  在八进制前加0, 十六进制前显示0x或0X, 取决于用的是x或X    比如: “integer:%#X!” % 1984</li>
<li>
(var)    映射变量(字典参数)</li>
<li>
m.n   m是显示的最小总宽度, n是小数点后的位数</li>
</ol>
</li>
<li>
格式化字符串接收dict数据:”%(howmany)d days” % {“howmany”: 28}</li>
<li>
字符串模板 s = Template(&#8216;There are ${howmany} ${lang} Quotation Symbols&#8217;)</p>
<ol>
<li>
s.substitute([key = value, key = value…])  这个函数必须提供所有的占位参数, 否则报错</li>
<li>
s.safe_substitute([key = value, key = value…])  和substitute功能是一样的, 都是转成得到一个字符串, 但是这个方法对参数没有要求, 如果没有提供对应的参数, 就直接输出.</li>
</ol>
</li>
<li>
原始字符串操作符(r/R), 紧贴字符串左引号, 不区分大小写. 用来使字符串描述各自原始的意义, 而不使用转义</li>
<li>
使用正则查找空白字符: m = re.search(r&#8217;\\[rtfvn]&#8216;, r&#8217;Hello World!\n&#8217;)…</li>
<li>
可以使用u | U &#8216;字符串&#8217;的方式创建unicode字符串, 该标识可以和r/R连用</li>
<li>
python参数有位置参数和关键字参数两种, 位置参数在定义时只有参数名, 关键字参数定义时是key=value的形式</li>
<li>
python也提供可变参, *为位置可变参, **为关键字可变参</li>
<li>
如果使用* | **方式传递实参, * 可以将序列参数转变成每个元素作为单独参数, **则可以将dict转换成关键字参数</li>
<li>
内建函数</p>
<ol>
<li>
cmp, 使用字符的ascii值进行比较(Unicode字符串按照unicode值比较)</li>
<li>
max, min, len, enumerate, zip, 其中zip可以接受多个参数, 按照下面方式返回:</li>
</ol>
<p>zip(“abcd”, “efg”, “hijk”, “lmn”) 返回: [('a', 'e', 'h', 'l'), ('b', 'f', 'i', 'm'), ('c', 'g', 'j', 'n')]</p>
<ol>
<li>
str和unicode都是basestring的特化类, 但是, Unicode又包含(类之间仅仅是兄弟关系, 元素范围上有包含关系)str的表示范围</li>
<li>
chr(number), unichr(number), ord(string), chr和unichr分别用来把一个数字转换成一个对应类型的字符串, ord则是将一个string类型的单字符对象转换成为对应的ascii码或unicode编码</li>
</ol>
</li>
<li>
string模块的重要函数, 所有这些函数, 都可以省略第一个参数, 使用string.func的方式调用</p>
<ol>
<li>
string.index()和string.find()方法是一样的功能, 但是, index方法在查找不到字符串的时候, 会报一个异常, string.rfind(), string.rindex()用法相同, 是从右边开始查找</li>
<li>
string.join(sequence[, str]) 如果只有一个参数, 返回一个将所有元素插空一个空格的字符串(如果是序列, 转换成为字符串), 如果有两个参数, 把第二个参数向第一个参数的每个空位进行插空</li>
<li>
string.ljust(string, width[, fillchar])  填充fillchar(只能是一个字符)width个到string后面, 使string左对齐, 如果fillchar空, 填充空格, rjust为右对齐</li>
<li>
string.lower(), string.upper(), string.swapcase()大小写转换</li>
<li>
string.lstrip(), string.rstrip(), string.strip()  去除空格.</li>
<li>
string.split(string, sub, count)  将string截取sub, 从左向右截取count个, 返回list</li>
<li>
string.replace(string, old, new[, number=string.count(string, old)])  将string的old子串替换成new, 最多替换不超过number, number默认是old在string的数量</li>
<li>
string.translate</li>
<li>
string.zfill(string, width)  用width个0填充string的左面使其右对齐</li>
</ol>
</li>
<li>
unicode.encode(CODE_STRING) 按照指定编码方式编码字符串, decode反之, 按照指定编码方式解码</li>
<li>
除了pickle模块之外, 其他模块都已经支持unicode..</li>
<li>
UnicodeError异常在exceptions模块中定义, 是ValueError的子类, 所有关于Unicode编解码的异常都要继承自UnicodeError</li>
<li>
与字符串类型有关的模块:</p>
<ol>
<li>
string: 字符串相关操作函数和工具, 比如Template类</li>
<li>
re:  正则表达式</li>
<li>
struct: 字符串和二进制之间的转换</li>
<li>
c/StringIO  字符串缓冲对象, 操作方法类似于file对象</li>
<li>
base64  Base16, 32, 64数据编解码</li>
<li>
codecs   解码器注册和基类</li>
<li>
crypt  进行单方面加密</li>
<li>
difflib   找出序列间的不同</li>
<li>
hashlib   多种不同安全哈希算法和信息摘要算法的API</li>
<li>
hma    HMAC信息鉴权算法的python实现</li>
<li>
md5  RSA的MD5信息摘要鉴权</li>
<li>
rotor   提供多平台的加解密服务</li>
<li>
sha    NIAT的安全哈希算法SHA</li>
<li>
stringprep   提供用于IP协议的Unicode字符串</li>
<li>
textwrap   文本打包和填充</li>
<li>
unicodedata    Unicode数据库</li>
</ol>
</li>
<li>
字符串的关键点:</p>
<ol>
<li>
不可分字符类型</li>
<li>
类似printf()的格式化字符串</li>
<li>
三引号内可以接受特殊字符(What You See Is What You Get)</li>
<li>
r | R原始字符串</li>
<li>
python字符串不通过NUL或者\0结束</li>
</ol>
</li>
<li>
list的元素删除</p>
<ol>
<li>
del list[index]  根据index删除list中的元素</li>
<li>
list.remove(value)   从list中移除值是value的第一个元素</li>
<li>
list.pop()   类似栈的出栈操作, 弹出栈顶并返回</li>
</ol>
</li>
<li>
list的成员关系操作还是使用in | not in</li>
<li>
列表解析: [var_name for var_name in list if expression]if之后和for之前都可以使用var_name进行运算</li>
<li>
列表的比较操作, 隐式调用cmp方法, 比较规则是逐个扫描元素, 进行比较, 如果可以比较, 比较, 如果相等扫描下一个元素, 如果不相等返回结果, 如果两个元素类型不可以比较, 就比较两个对象的id()值.. 如果一直相等 ,直到一个列表扫描结束, 那么返回较长的列表较大</li>
<li>
序列类型函数</p>
<ol>
<li>
len(), max(), min()</li>
<li>
sorted() 和reversed()  返回的是被排序或逆序之后的序列, 不会改变序列本身的引用, 而序列自己的成员方法则会改变自身</li>
<li>
enumerate()  返回一个key=&gt;value方式的enumerate对象</li>
<li>
zip()  将多个列表压缩成为一个元组列表…..zip返回的元组列表可以使用足够元组内元素数量的参数来迭代遍历每一个元素, 例如: for a, b, c, d in zip(alist, blist, clist, dlist)</li>
<li>
使用list()和tuple()可以完成列表和元组之间的转换, 但是这种转换是值的转换, 所以他们是==的, 但是不是is的</li>
<li>
extend(列表)方法接受另外一个列表追加到原列表之后</li>
<li>
list.pop(index = -1)  list的pop可以弹出指定索引的值</li>
</ol>
</li>
<li>
处理一组对象的时候, 默认的是创建一个元组, 例如a = 1, 2, 3, 4 实际上是创建了一个元组(1, 2, 3, 4)</li>
<li>
单独使用del删除一个元组元素是不可行的, 只能通过重组</li>
<li>
元组的可变性: 元组的某一个元素指向了一个对象, 该对象是可变的, 那么改变该对象就相当于改变了元组的内容, 然而, 真正的我们的元组确实是没有改变的. It&#8217;s so wizardly. 为什么呢? 元组内部持有的是对方的引用, 那个对象无论怎么变都还是在那里, 所以, 元组内部的值(内存地址)是没有改变的.</li>
<li>
函数可以返回多对象, 返回的实际也是一个元组</li>
<li>
单元素元组使用括号创建时需要在后面显示的加上”, “, 由于括号被重载作为一个分组操作符了, 在这里会优先使用分组功能, 所以, 返回的总是原始类型</li>
<li>
相关模块:</p>
<ol>
<li>
数组array   受限的可变序列类型, 要求所有元素都是相同的类型</li>
<li>
operator   包含函数调用形式的序列操作符, operator.concat(m, n)相当于m+n</li>
<li>
re  perl风格的正则查找</li>
<li>
StringIO / cStringIO  长字符串作为文件来操作, 比如read(),  seek()函数……c版本的速度更快一些</li>
<li>
Textwrap  包裹/填充文本的函数</li>
<li>
types   包含python支持的所有类型</li>
<li>
collections  高性能容器数据类型</li>
<li>
UserList  包含了list对象的完全的类实现, 允许用户获得类似list的类, 用以派生新的类和功能</li>
</ol>
</li>
<li>
浅拷贝: 拷贝原对象中的内容, 但是新创建对象. 比如一个list的浅拷贝就是把list中元素的引用值拷贝过去…  浅拷贝实例: 完全切片操作, 利用工厂函数, 使用copy模块的copy函数</li>
<li>
深拷贝: 拷贝源对象中的内容, 如果某个属性(或序列中的元素)是可变对象, 把该可变对象的内容也进行拷贝</li>
<li>
非容器类型对象没有拷贝一说</li>
<li>
可变参: f(*args1, **args2), 如果关键字可变参不指定key值, 会被作为位置参数和前面的参数放到一个元组中….位置可变参在倒数第二个位置, 关键字可变参在倒数第一个位置.</li>
<li>
map(function, iterable), 应用function在iterable的每一个元素, 返回值作为新的序列的元素</li>
</ol>
<hr /><h2>Comments</h2><ul><li><a href="http://tossp.com/python-study-notes-chapter-6.html">2010 年 05 月 26 日</a>, <a href='http://zww.me' rel='external nofollow' class='url'>zwwooooo</a> writes: 看不懂，沙发！</li></ul><hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(7章)">PyThon学习笔记(7章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

映射和集合类型(chapter7)

	
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表
	
字典的创建和赋值

	
dict = {key: value}
	
dict = dict((key, value), (key,</li><li><a href="http://tossp.com/python-study-notes-chapter-5.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(5章)">PyThon学习笔记(5章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

数字(chapter5)

	
支持的数字类型: 整型, 长整型, 布尔型, 双精度浮点型, 十进制浮点型和复数
	
整型

	
布尔型  包含True和False两个值的整型
	
标准整数类型  0x表示十六进制,</li><li><a href="http://tossp.com/python-study-notes.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(1, 2章)">PyThon学习笔记(1, 2章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

	
Python.exe 的解释器options:

	
–d   提供调试输出
	
–O   生成优化的字节码(生成.pyo文件)
	
–S  </li><li><a href="http://tossp.com/python-study-notes-chapter-4.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(4章)">PyThon学习笔记(4章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
python对象(chapter4)

	
python对象有三个特征: 身份和类型是只读的, 如果对象支持不支持更新操作, 那么值也就是只读的.

	
身份: 唯一的身份标识, 可以使用内建函数id()得到, 可以看作是对象的内存地址…
	
类型: 对象的类型决定该对象保存什么类型的值, 可以进行什么操作, 遵循什么规则.,</li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes-chapter-6.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyThon学习笔记(5章)</title>
		<link>http://tossp.com/python-study-notes-chapter-5.html</link>
		<comments>http://tossp.com/python-study-notes-chapter-5.html#comments</comments>
		<pubDate>Sat, 22 May 2010 16:50:37 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/?p=2138</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:43最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
数字(chapter5)

<div class="clear"></div><a href="http://tossp.com/python-study-notes-chapter-5.html" title="PyThon学习笔记(5章)" rel="external" class="more-link">阅读全文-—共1868字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:43</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>数字(chapter5)</h1>
<ol>
<li>
支持的数字类型: 整型, 长整型, 布尔型, 双精度浮点型, 十进制浮点型和复数</li>
<li>
整型</p>
<ol>
<li>
布尔型  包含True和False两个值的整型</li>
<li>
标准整数类型  0x表示十六进制, 无前缀表示十进制, 0表示八进制, 0b表示二进制</li>
<li>
长整型  整数后加L, 表示范围与可用内存大小有关..</li>
</ol>
</li>
<li>
双精度浮点数: 一个符号位, 52个底位, 11个指数位. 使用后缀e表示指数</li>
<li>
复数: 实数 + 序数J构成一个复数</p>
<ol>
<li>
python中的复数概念</p>
<ol>
<li>
虚数不能单独存在, 总是和一个值为0.0的实数部分一起构成一个复数</li>
<li>
复数由实数部分和虚数部分组成</li>
<li>
表示虚数的语法: real + imagJ</li>
<li>
实数部分和虚数部分都是浮点数</li>
<li>
虚数部分必须有后缀j或J</li>
</ol>
</li>
<li>
复数的内建属性</p>
<ol>
<li>
real 复数的实部</li>
<li>
imag 复数的虚部</li>
<li>
conjugate() 返回该复数的共轭复数</li>
</ol>
</li>
</ol>
</li>
<li>
强制类型转换规则</li>
</ol>
<ol>
<li>
python提供python解释器的启动参数Qdivision_style, -Qnew执行新的除法行为, -Qold执行传统除法行为, 默认是-Qold…-Qwarn和-Qwarnall可以用来度过过渡期</li>
<li>
幂运算符** 比左侧单目运算符优先级高, 比右侧单目运算符优先级高</li>
<li>
位运算符: ~, &amp;, |, ^, &lt;&lt;, &gt;&gt;</p>
<ol>
<li>
负数会被当成正数的二进制补码处理</li>
<li>
左移和右移N位等同与无溢出检查的2的N次幂运算</li>
<li>
长整数的位运算使用一种经过修改的二进制补码形式, 使的符号位可以无限左移</li>
<li>
~是单目运算符</li>
</ol>
</li>
<li>
内建函数和工厂函数</p>
<ol>
<li>
数字类型函数:</p>
<ol>
<li>
转换工厂函数: int(), long(), float(), complex(), 接受参数第一个是要转换的值, 第二个是进制..如果要转换的值是string才能使用第二个函数指定进制.</p>
<ol>
<li>
python2.2开始, 加入了bool(), 用来将整数1和0转换成为标准布尔值(所有非0数都返回True).</li>
<li>
python2.3的标准数据类型添加了Boolean类型, true和false也有了常量值True和False, 而不再是1和0</li>
<li>
bool(obj) 返回obj对象的布尔值, 也就是obj.__nonzero__()</li>
<li>
complex(real, imag=0.0)</li>
</ol>
</li>
<li>
功能函数</p>
<ol>
<li>
abs(number) 返回数字的绝对值, 如果是复数, 返回math.sqrt(num.real2 + num.imag2)</li>
<li>
coerce(number1, number2): 返回按照类型转换规则转换得到的两个数字组成的元组</li>
<li>
divmod(number1, number2)  返回一个包含商和余数的元组, 整数返回地板除和取余操作结果, 浮点数返回的商部分是math.floor(number1/number2), 复数的商部分是ath.floor((number1/number2).real)</li>
<li>
pow()和**功能相同</li>
<li>
round(number[, base]) 对浮点数进行四舍五入运算, base参数是小数位参数, 如果不指定, 返回与第一个参数最接近的整数的浮点形式</li>
<li>
int() 直接去掉小数部分, floor()得到最接近但小于原数的整数, round()得到最接近原数的整数</li>
</ol>
</li>
<li>
整数的内建函数: hex(), oct(), bin()…ord(“A”) 接受一个ascii或unicode字符, 返回相应的unicode值 <span style="font-family: Wingdings;">?è</span> char(65L)接受unicode码值, 返回对应的unicode字符.</li>
</ol>
</li>
</ol>
</li>
<li>
其他数字类型</p>
<ol>
<li>
布尔数:</p>
<ol>
<li>
布尔型是整型的子类, 但是不能再被继承而生成它的子类.</li>
<li>
没有__nonzero__()方法的对象默认值是True</li>
<li>
对于值为0的任何数字或空集(空的list|tuple|dict)在python中值都是False</li>
<li>
数学运算中, True ==1, False == 0</li>
</ol>
</li>
<li>
十进制浮点数: from decimal import Decimal</li>
</ol>
</li>
<li>
数字科学计算的包</p>
<ol>
<li>
高级的Third package: Numeric(NumPy)</li>
<li>
python自带的数字类型相关模块</p>
<ol>
<li>
decimal  十进制浮点运算类Decimal</li>
<li>
array  高效数值数组(字符, 整数, 浮点数)</li>
<li>
match/cmatch  标准c库数学运算函数. 常规数学运算在match, 复数运算在cmatch</li>
<li>
operator  数字运算符的函数实现</li>
<li>
random  伪随机数生成器</p>
<ol>
<li>
randint(start, end)随机生成start, end之间的一个整数</li>
<li>
uniform(start, end)随机生成范围内的一个浮点数</li>
<li>
randrange([start ,]stop[, step])随机生成start, stop内按step步增数字范围的一个整数</li>
<li>
choice(sequence)随机返回给定的序列中的一个元素</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<hr /><h2>Comments</h2><ul><li><a href="http://tossp.com/python-study-notes-chapter-5.html">2010 年 05 月 23 日</a>, <a href='http://an9.name' rel='external nofollow' class='url'>an9</a> writes: 技术贴，纯路过。</li></ul><hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(7章)">PyThon学习笔记(7章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

映射和集合类型(chapter7)

	
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表
	
字典的创建和赋值

	
dict = {key: value}
	
dict = dict((key, value), (key,</li><li><a href="http://tossp.com/python-study-notes.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(1, 2章)">PyThon学习笔记(1, 2章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

	
Python.exe 的解释器options:

	
–d   提供调试输出
	
–O   生成优化的字节码(生成.pyo文件)
	
–S  </li><li><a href="http://tossp.com/python-study-notes-chapter-4.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(4章)">PyThon学习笔记(4章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
python对象(chapter4)

	
python对象有三个特征: 身份和类型是只读的, 如果对象支持不支持更新操作, 那么值也就是只读的.

	
身份: 唯一的身份标识, 可以使用内建函数id()得到, 可以看作是对象的内存地址…
	
类型: 对象的类型决定该对象保存什么类型的值, 可以进行什么操作, 遵循什么规则.,</li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li><li><a href="http://tossp.com/python-study-notes-3-chapters.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(3章)">PyThon学习笔记(3章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
Python基础(chapter3)

	
setence and syntax语句和语法

	
#为注释符号
	
n是标准行分隔符, 通常一个语句一行
	
反斜线表示下一行继续, 用来将单条语句放入多行…尽量使用括号代替
	
分号;表示将两个语句连接在一行中…不提倡
	
冒号:表示将代码块的头和体分开
	
语句(代码块)用缩进块方式体现: 同一个代码组的代码必须严格左对齐..由于不同的editor制表符宽度不一, 为了使代码跨平台, 推荐使用4个空格缩进
	
不同缩进深度分隔不同的代码块
	
python文件以模块的形式组织: 模块以磁盘文件的形式存在, 不应该让某个模块充斥的太大


	
赋值

	
赋值语句没有返回值,</li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes-chapter-5.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PyThon学习笔记(4章)</title>
		<link>http://tossp.com/python-study-notes-chapter-4.html</link>
		<comments>http://tossp.com/python-study-notes-chapter-4.html#comments</comments>
		<pubDate>Thu, 20 May 2010 16:47:20 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/?p=2137</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:41最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
python对象(chapter4)

<div class="clear"></div><a href="http://tossp.com/python-study-notes-chapter-4.html" title="PyThon学习笔记(4章)" rel="external" class="more-link">阅读全文-—共2643字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:41</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>python对象(chapter4)</h1>
<ol>
<li>
python对象有三个特征: 身份和类型是只读的, 如果对象支持不支持更新操作, 那么值也就是只读的.</p>
<ol>
<li>
身份: 唯一的身份标识, 可以使用内建函数id()得到, 可以看作是对象的内存地址…</li>
<li>
类型: 对象的类型决定该对象保存什么类型的值, 可以进行什么操作, 遵循什么规则., 可以使用内建函数type()查看python对象的类型.</li>
<li>
值: 对象表示的数据项</li>
</ol>
</li>
<li>
对象属性: 主要有属性, 值, 相关联的可执行代码(method), 一些python类型也有数据属性, 含有数据属性的对象包括但不限于: 类, 类实例, 模块, 复数, 文件.</li>
<li>
基础数据类型: 数字, 整形, 布尔型, 长整型, 浮点型, 复数型, 字符串, 列表, 元组, 字典.</li>
<li>
其他内建类型: 类型, None, 文件, 集合/固定集合, 函数/方法, 模块, 类</p>
<ol>
<li>
type(type(1)) 可以看出类型对象本身也是对象, 它的类型是type</li>
<li>
None的类型是NoneType, NoneType只有一个值, 就是None, 不支持任何运算也没有任何内建方法, 布尔值总返回False</li>
</ol>
</li>
<li>
每个对象天生都有布尔值, 以下对象的布尔值是False</p>
<ol>
<li>
None</li>
<li>
False(bool类型)</li>
<li>
所有值为0的数</li>
<li>
” 空字符串</li>
<li>
[] | () | {} 空列表, 空元组, 空字典</li>
<li>
用户创建的实例如果定义了nonzero(__nonzero__())或length(__len__())且值为0, 那么返回的布尔值也是False</li>
</ol>
</li>
<li>
当要获取一个对象的布尔值的时候, 首先会调用__nonzero__(必须返回布尔类型或者int类型.)方法, 如果实现了该方法, 就返回该方法返回的布尔值, 如果没有实现该方法, 继续调用__len__方法(该方法返回值必须是大于等于0的), 如果实现了__len__方法, 就根据其返回值返回布尔值.</li>
<li>
内部类型: python内部机制</p>
<ol>
<li>
代码: 编译过的python的源代码片段, 是可执行对象. 通过调用内建函数compile()可以得到代码对象. 代码对象可以被exec命令或eval()内建函数来执行.   代码是用户自定义函数的核心, 运行期获得上下文..  __code__是函数的一个属性, 函数除了代码这个属性, 还有函数名, 文档字符串, 默认参数, 全局命名空间等必须的属性</li>
<li>
帧对象: 用于跟踪记录对象</li>
<li>
跟踪记录: 用于异常发生时, 程序访问跟踪记录对象处理程序.</li>
<li>
切片:</p>
<ol>
<li>
步进切片sequence[::number] number为负数, 倒序显示字符串, 正数则正序显示字符串, 数值代表显示字符的step值.</li>
<li>
多维切片 sequence[start1: end1, start2: end2]</li>
<li>
省略切片 sequence[…, start1: end1]</li>
<li>
切片对象 使用slice([start, ]stop[, step])可以创建一个切片对象</li>
</ol>
</li>
<li>
省略对象: 用于扩展切片语法, 起记号作用..在切片语法中表示省略号, 省略对象有一个唯一的名字Ellipsis, 布尔值始终是True</li>
<li>
Xrange: 调用xrange()生成Xrange对象, 类似内建函数range, 用于节省内存使用或range无法完成的超大数据集场合</li>
</ol>
</li>
<li>
标准类型运算符</p>
<ol>
<li>
对象值比较</p>
<ol>
<li>
数字根据大小比较</li>
<li>
字符串根据字符先后顺序比较</li>
<li>
list | tuple | dict顺序按照其中元素(dict按照键)比较</li>
<li>
链式比较相当于多个比较使用and连接</li>
<li>
自定义类型对象的比较是引用值比较, 也就是id(object_name)的比较</li>
</ol>
</li>
<li>
对象身份比较</p>
<ol>
<li>
is / is not用来比较两个别名是否引用同一个对象</li>
<li>
整数对象和字符串对象是不可变对象…</li>
</ol>
</li>
<li>
布尔类型运算符: and, or, not</li>
</ol>
</li>
<li>
标准类型内建函数</p>
<ol>
<li>
cmp(obj1, obj2)  比较obj1和obj2, 根据比较结果返回整数i, i&lt;0 <span style="font-family: Wingdings;">à</span> obj1&lt;obj2, i&gt;0 <span style="font-family: Wingdings;">à</span> obj1&gt;obj2, i==0 <span style="font-family: Wingdings;">à</span> obj1 == obj2….自定义类型中通过定义方法__cmp__(target)来实现….使用比较运算符, 或直接调用cmp时该方法被调用</li>
<li>
type(obj)  得到一个对象的类型, 返回相应的type对象</li>
<li>
str(obj)  返回对象适合可读性好的字符串表示…在自定义类中使用__str__(self)返回一个字符串, 调用str(obj)时会被隐式调用</li>
<li>
repr(obj)  返回一个对象的字符串表示, repr返回的字符串通常可以被用于使用eval动态创建一个对象.  通常 obj == eval(repr(obj))是成立的</li>
<li>
“, 反单引号, `obj`和repr(obj)做的事情是一样的.</li>
<li>
isinstance(obj, (type[, type, …]))  判断obj是不是第二个参数tuple中的列举的类型的实例</li>
<li>
types模块提供一些已知的类型</li>
<li>
由于每一种类型都只有一个类型对象, 所以, 可以使用引用比较代替值比较以提升性能: 用if type(num) is types.IntType 替代if type(num) == types.IntType</li>
<li>
from-import: 只引入某个模块的一部分属性: 比如from types import IntType 这样做可以有效的减少查询次数</li>
<li>
python的operator模块中有绝大多数运算符对应的同功能的函数可供使用.</li>
</ol>
</li>
<li>
类型工厂函数: int(), long(), float(), complex(), str(), Unicode(), basestring(), list(), tuple(), type(), dict(), bool(), set(), frozenset(), object(), classmethod(), staticmethod(), super(), property(), file()</li>
<li>
标准类型的分类:</p>
<ol>
<li>
标准类型是”基本内建数据对象原始类型”</p>
<ol>
<li>
基本: 是python的标准或核心</li>
<li>
内建: python默认提供</li>
<li>
数据: 用于一般数据存储</li>
<li>
对象: 对象是数据和功能的默认抽象</li>
<li>
原始: 这些类型提供的是最底层的粒度数据存储</li>
<li>
类型: 本身就是数据类型</li>
</ol>
</li>
<li>
按存储模型进行分类:</p>
<ol>
<li>
标量/原子类型: 数值, 字符串等可以存储单一字面对象的类型.</li>
<li>
容器类型: 列表, 元素, 字典等可以存储多个字面变量的类型, python中的容器类型都可以存储不同类型的元素</li>
</ol>
</li>
<li>
按更新模型进行分类:  对象创建之后, 值不可以改变, 注意: 这里是对象, 而不是变量</p>
<ol>
<li>
可变类型: 列表, 字典</li>
<li>
不可变类型: 数字, 字符串, 元组</li>
</ol>
</li>
<li>
按访问模型进行分类: 访问对象的方式</p>
<ol>
<li>
直接访问: 数值</li>
<li>
顺序访问: 列表, 元组, 字符串等可以按照索引访问的类型</li>
<li>
映射访问: 字典</li>
</ol>
</li>
</ol>
</li>
<li>
不支持的类型: char, byte, pointer</li>
</ol>
<hr /><h2>Comments</h2><ul><li><a href="http://tossp.com/python-study-notes-chapter-4.html">2010 年 05 月 21 日</a>, 砳砳 writes: 已阅。</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html">2010 年 05 月 21 日</a>, <a href='http://tossp.com/' rel='external nofollow' class='url'>砼砼</a> writes: @<a href="#comment-7591" rel="nofollow">砳砳:</a>请领导指示！</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html">2010 年 05 月 21 日</a>, <a href='http://zww.me' rel='external nofollow' class='url'>zwwooooo</a> writes: 我不懂，我飘，我走</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html">2010 年 05 月 22 日</a>, <a href='http://axiu.me' rel='external nofollow' class='url'>阿修</a> writes: 这个语言听说很不错，没试过</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html">2010 年 05 月 22 日</a>, <a href='http://www.waihuiblog.com' rel='external nofollow' class='url'>博客外汇</a> writes: 最近正在用PyThon开发一个通讯软件，呵呵！楼主解释的不错</li></ul><hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(7章)">PyThon学习笔记(7章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

映射和集合类型(chapter7)

	
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表
	
字典的创建和赋值

	
dict = {key: value}
	
dict = dict((key, value), (key,</li><li><a href="http://tossp.com/python-study-notes-chapter-5.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(5章)">PyThon学习笔记(5章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

数字(chapter5)

	
支持的数字类型: 整型, 长整型, 布尔型, 双精度浮点型, 十进制浮点型和复数
	
整型

	
布尔型  包含True和False两个值的整型
	
标准整数类型  0x表示十六进制,</li><li><a href="http://tossp.com/python-study-notes.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(1, 2章)">PyThon学习笔记(1, 2章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

	
Python.exe 的解释器options:

	
–d   提供调试输出
	
–O   生成优化的字节码(生成.pyo文件)
	
–S  </li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li><li><a href="http://tossp.com/python-study-notes-3-chapters.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(3章)">PyThon学习笔记(3章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
Python基础(chapter3)

	
setence and syntax语句和语法

	
#为注释符号
	
n是标准行分隔符, 通常一个语句一行
	
反斜线表示下一行继续, 用来将单条语句放入多行…尽量使用括号代替
	
分号;表示将两个语句连接在一行中…不提倡
	
冒号:表示将代码块的头和体分开
	
语句(代码块)用缩进块方式体现: 同一个代码组的代码必须严格左对齐..由于不同的editor制表符宽度不一, 为了使代码跨平台, 推荐使用4个空格缩进
	
不同缩进深度分隔不同的代码块
	
python文件以模块的形式组织: 模块以磁盘文件的形式存在, 不应该让某个模块充斥的太大


	
赋值

	
赋值语句没有返回值,</li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes-chapter-4.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PyThon学习笔记(3章)</title>
		<link>http://tossp.com/python-study-notes-3-chapters.html</link>
		<comments>http://tossp.com/python-study-notes-3-chapters.html#comments</comments>
		<pubDate>Tue, 18 May 2010 16:44:17 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/?p=2136</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:41最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
Python基础(chapter3)

<div class="clear"></div><a href="http://tossp.com/python-study-notes-3-chapters.html" title="PyThon学习笔记(3章)" rel="external" class="more-link">阅读全文-—共2413字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:41</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>Python基础(chapter3)</h1>
<ol>
<li>
setence and syntax语句和语法</p>
<ol>
<li>
#为注释符号</li>
<li>
\n是标准行分隔符, 通常一个语句一行</li>
<li>
反斜线\表示下一行继续, 用来将单条语句放入多行…尽量使用括号代替</li>
<li>
分号;表示将两个语句连接在一行中…不提倡</li>
<li>
冒号:表示将代码块的头和体分开</li>
<li>
语句(代码块)用缩进块方式体现: 同一个代码组的代码必须严格左对齐..由于不同的editor制表符宽度不一, 为了使代码跨平台, 推荐使用4个空格缩进</li>
<li>
不同缩进深度分隔不同的代码块</li>
<li>
python文件以模块的形式组织: 模块以磁盘文件的形式存在, 不应该让某个模块充斥的太大</li>
</ol>
</li>
<li>
赋值</p>
<ol>
<li>
赋值语句没有返回值, 但可以使用链式赋值</li>
<li>
python2.0开始支持增量赋值(算符和等号连接赋值), 但是python不支持++, &#8211;</li>
<li>
赋值操作中, 可变对象会被直接修改(引用位置值的修改), 不可变对象则被重新赋予新的对象(引用修改)</li>
<li>
多元赋值: a, b, c = 1, 2, &#8216;string&#8217;, 建议使用tuple的方式进行多元赋值: (a, b, c) = (1, 2, &#8216;string&#8217;)</li>
</ol>
</li>
<li>
swap操作: x, y = y, x</li>
<li>
标识符</p>
<ol>
<li>
大小写敏感</li>
<li>
python的关键字列表和iskeyword()函数在keyword模块, 方便查阅</li>
<li>
内建: built-in可以看作是系统保留字….对于一些内建函数需要覆盖(重定义, 替换)…built-in是__builtins__模块的成员, 该模块由解释器自动导入</li>
<li>
python不支持重载</li>
<li>
下划线: 作为变量前缀和后缀指定特殊变量</p>
<ol>
<li>
_xxx: 不用&#8217;from module import*&#8217;导入</li>
<li>
__xxx__: 系统定义名字</li>
<li>
_xxx: 类中的私有变量名</li>
</ol>
</li>
</ol>
</li>
<li>
python之禅</li>
</ol>
<p>The Zen of Python, by Tim Peters</p>
<p>python之禅. 作者Tim Peters</p>
<p>Beautiful is better than ugly.</p>
<p>漂亮胜于丑陋</p>
<p>Explicit is better than implicit.</p>
<p>详尽胜于含蓄</p>
<p>Simple is better than complex.</p>
<p>简单胜于复杂</p>
<p>Complex is better than complicated.</p>
<p>组合胜于复杂(结构)</p>
<p>Flat is better than nested.</p>
<p>单一胜于嵌套</p>
<p>Sparse is better than dense.</p>
<p>稀少胜于繁杂</p>
<p>Readability counts.</p>
<p>可读性价值</p>
<p>Special cases aren&#8217;t special enough to break the rules.</p>
<p>特例不足以违反规则</p>
<p>Although practicality beats purity.</p>
<p>实践胜于理论</p>
<p>Errors should never pass silently.</p>
<p>错误可能从不沉默</p>
<p>Unless explicitly silenced.</p>
<p>除非明白沉默</p>
<p>In the face of ambiguity, refuse the temptation to guess.</p>
<p>面对歧义, 不被猜想诱惑</p>
<p>There should be one&#8211; and preferably only one &#8211;obvious way to do it.</p>
<p>可能仅有一种更好的方法</p>
<p>Although that way may not be obvious at first unless you&#8217;re Dutch.</p>
<p>Now is better than never.</p>
<p>现在胜于一切</p>
<p>Although never is often better than *right* now.</p>
<p>If the implementation is hard to explain, it&#8217;s a bad idea.</p>
<p>难于解释的实现是不好的</p>
<p>If the implementation is easy to explain, it may be a good idea.</p>
<p>易于明白的实现可能是个好方案</p>
<p>Namespaces are one honking great idea &#8212; let&#8217;s do more of those!</p>
<p>名空间是一个好方案, 让我们去超越这些</p>
<ol>
<li>
模块组织</li>
</ol>
<p># 起始行</p>
<p># 模块文档</p>
<p># 模块导入</p>
<p># 变量定义</p>
<p># 类定义</p>
<p># 函数定义</p>
<p># 主程序</p>
<ol>
<li>
__name__用于指示模块应该如何被加载, 如果值是”__main__”说明是主模块, 如果是模块名, 说明是被导入的</li>
<li>
主模块测试代码</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># business process</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>__name__ <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'__main__'</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<ol>
<li>
内存管理</p>
<ol>
<li>
基本</p>
<ol>
<li>
弱类型 – 动态类型</li>
<li>
programmer不关心内存管理</li>
<li>
变量并会被回收</li>
<li>
del语句能够直接释放资源</li>
</ol>
</li>
<li>
变量未初始化不允许使用</li>
<li>
引用计数: 对于一个内存堆中的对象, 有多少个指针引用它..引用计数就是多少, 引用计数为0时, 该对象可以被垃圾回收器回收</p>
<ol>
<li>
增加</p>
<ol>
<li>
对象创建</li>
<li>
别名创建(引用赋值)</li>
<li>
参数传递(引用传值)</li>
<li>
被容器引用</li>
</ol>
</li>
<li>
减少</p>
<ol>
<li>
引用生命周期结束</li>
<li>
对象别名被显示销毁 del y</li>
<li>
对象别名被赋予其他引用</li>
<li>
窗口对象本身被销毁</li>
</ol>
</li>
<li>
del</p>
<ol>
<li>
从现在的名字空间中删除一个别名</li>
<li>
对象的引用计数减一</li>
</ol>
</li>
</ol>
</li>
<li>
垃圾回收: 有对象引用计数为0, 对象被显示告知需要销毁, 有内存消耗大户存在导致系统压力较大时, 垃圾回收机制运行, 清理需要回收的内存区域…垃圾回收机制还有一个循环垃圾回收器, 确保释放循环引用对象(a引用b, b引用a, 导致其引用计数永远不为0)</li>
</ol>
</li>
<li>
将引入的其他模块中常用的变量重新赋予一个本地别名(ls = os.linesep)不仅可以避免冗长的变量名, 又可以提高加载速度(因为现在是本地变量了)</li>
<li>
重要的其他模块</p>
<ol>
<li>
debugger: pdb允许设置断点, 逐行调试, 检查堆栈, 还支持事后调试</li>
<li>
logger: logging分紧急, 错误, 警告, 信息, 调试五级日志</li>
<li>
profilers: 性能测试器</p>
<ol>
<li>
profile: python编写, 测试函数执行时间, 每次脚本执行总时间.</li>
<li>
hotshot: python2.2, c编写, 解决了性能测试过载问题, 但需要更多时间生成结果, python2.5修正了hotshot的时间计量bug</li>
<li>
cProfile: python2.5, c编写, 需要较长时间从日志文件载入分析结果, 不支持子函数状态细节, 某些结果不准</li>
</ol>
</li>
</ol>
</li>
</ol>
<hr /><h2>Comments</h2><ul><li><a href="http://tossp.com/python-study-notes-3-chapters.html">2010 年 05 月 20 日</a>, <a href='http://www.a-shun.com/' rel='external nofollow' class='url'>A.shun</a> writes: 不懂编程的路过。。。
捅捅好好学习</li><li><a href="http://tossp.com/python-study-notes-3-chapters.html">2010 年 05 月 21 日</a>, 禅宗少林 writes: PyThon 好学吗？以前看过类似的文章。</li><li><a href="http://tossp.com/python-study-notes-3-chapters.html">2010 年 05 月 21 日</a>, <a href='http://tossp.com/' rel='external nofollow' class='url'>砼砼</a> writes: @<a href="#comment-7589" rel="nofollow">A.shun:</a>.....................你强大shun。。。。。。。。</li><li><a href="http://tossp.com/python-study-notes-3-chapters.html">2010 年 05 月 21 日</a>, <a href='http://tossp.com/' rel='external nofollow' class='url'>砼砼</a> writes: @<a href="#comment-7596" rel="nofollow">禅宗少林:</a>还行吧，学简单，学会很难，呵呵</li></ul><hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(7章)">PyThon学习笔记(7章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

映射和集合类型(chapter7)

	
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表
	
字典的创建和赋值

	
dict = {key: value}
	
dict = dict((key, value), (key,</li><li><a href="http://tossp.com/python-study-notes.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(1, 2章)">PyThon学习笔记(1, 2章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

	
Python.exe 的解释器options:

	
–d   提供调试输出
	
–O   生成优化的字节码(生成.pyo文件)
	
–S  </li><li><a href="http://tossp.com/cost-chapters-focus-of-examination.html" rel="bookmark" title="Permanent Link: 造价员考试章节重点">造价员考试章节重点</a><br /></li><li><a href="http://tossp.com/chongqing-city-in-2008-denominated-fixed-chapters-note.html" rel="bookmark" title="Permanent Link: 重庆市2008计价定额章节说明">重庆市2008计价定额章节说明</a><br /></li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(1, 2章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/23/11315316.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(1, 2章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes-3-chapters.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PyThon学习笔记(1, 2章)</title>
		<link>http://tossp.com/python-study-notes.html</link>
		<comments>http://tossp.com/python-study-notes.html#comments</comments>
		<pubDate>Mon, 17 May 2010 15:24:52 +0000</pubDate>
		<dc:creator>砼砼</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[打死电脑]]></category>
		<category><![CDATA[杂七杂八]]></category>
		<category><![CDATA[代码]]></category>
		<category><![CDATA[学习]]></category>

		<guid isPermaLink="false">http://tossp.com/python-study-notes.html</guid>
		<description><![CDATA[这篇日志在2011-10-31 01:39:40最后一次修订。首先要说明，这套笔记不是我整理
有朋友知道原文出去麻烦告知一声，谢谢
基本配置及基础语法

<div class="clear"></div><a href="http://tossp.com/python-study-notes.html" title="PyThon学习笔记(1, 2章)" rel="external" class="more-link">阅读全文-—共3547字</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<div class="revised alert">这篇日志在<abbr title="星期一, 十月 31st, 2011, 1:39 上午">2011-10-31 01:39:40</abbr>最后一次修订。</div><br /><p>首先要说明，这套笔记不是我整理</p>
<p>有朋友知道原文出去麻烦告知一声，谢谢</p>
<h1>基本配置及基础语法</h1>
<ol>
<li>
Python.exe 的解释器options:</p>
<ol>
<li>
–d   提供调试输出</li>
<li>
–O   生成优化的字节码(生成.pyo文件)</li>
<li>
–S   不导入site模块以在启动时查找python路径</li>
<li>
–v   冗余输出(导入语句详细追踪)</li>
<li>
–m mod 将一个模块以脚本形式运行</li>
<li>
–Q opt 除法选项(参阅文档)</li>
<li>
–c cmd 运行以命令行字符串心事提交的python脚本</li>
<li>
file   以给定的文件运行python脚本</li>
</ol>
</li>
<li>
_在解释器中表示最后一个表达式的值.</li>
<li>
print支持类c的printf格式化输出: print “%s is number %d!” % (“python”, 1)</li>
<li>
print的输入内容后面加逗号, 就会使其输入不换行</li>
<li>
把输出重定向到日志文件:</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">logfile <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;c:/1.log&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span> &nbsp; //打开文件c:/<span style="color: #ff4500;">1</span>.<span style="color: black;">log</span>使用a模式..即add<span style="color: #66cc66;">,</span> 添加.<br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #66cc66;">&gt;&gt;</span> logfile<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;Fatal error: invalid input!&quot;</span><span style="color: #66cc66;">;</span> &nbsp; //<span style="color: #66cc66;">&gt;&gt;</span>为重定向..将<span style="color: #ff7700;font-weight:bold;">print</span>的结果重定向到logfile<span style="color: #66cc66;">,</span> 输出内容是<span style="color: #483d8b;">&quot;Fatal error: invalid input!&quot;</span>…<br />
<br />
logfile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span> &nbsp;//关闭文件流…</div></div>
<ol>
<li>
程序输入: raw_input(“提示字符串”):</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #dc143c;">user</span> <span style="color: #66cc66;">=</span> <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;请输入您的姓名&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></div></div>
</li>
<li>
int(数值)…..将数值字符串转换成整数值…</li>
<li>
运算符:</p>
<ol>
<li>
+ &#8211; * / %是和其他语言相同的加减乘及取模运算.取余运算</li>
<li>
/ 在浮点取模中得到的结果是完整的浮点数</li>
<li>
// 在浮点取模中得到的结果是经过舍去运算的结果.</li>
<li>
** 是乘方</li>
<li>
&gt;&gt;和&lt;&lt;的移位运算也支持. 但不支持java中的&gt;&gt;&gt; 和&lt;&lt;&lt; 移位.</li>
<li>
&lt; &lt;= &gt; &gt;= ++ != &lt;&gt; 等比较运算符</li>
<li>
and or not 等逻辑运算符</li>
</ol>
</li>
<li>
变量和赋值: python是弱类型语言..</li>
<li>
list, tuple, map * 4 得到的结果是一个新的 list | tuple | map, 是原数据的4份</li>
<li>
数字:</p>
<ol>
<li>
int(有符号整数)</li>
<li>
long(长整数)</li>
<li>
bool(布尔值)</li>
<li>
float(浮点值)</li>
<li>
complex(复数)</li>
<li>
python2.3开始, 如果结果从int溢出, 会自动转型为long</li>
<li>
python2.4开始支持decimal数字类型, 需要导入decimal模块..由于在二进制表示中会有一个无限循环片段, 普通的浮点1.1实际是不能被精确表示的, 被表示为1.1000000000000001. 使用print decimal.Decimal(&#8217;1.1&#8242;);则可以得到精确的1.1</li>
</ol>
</li>
<li>
字符串:  引号之间的字符集合, 支持使用成对的单引号和双引号, 三引号(三个连续单引号或双引号)可以用来包含特殊字符.  使用索引运算符[]和切片运算符[ : ]可以得到子字符串…字符串中第一个字符的索引是0, 最后一个字符的索引是-1;</li>
<li>
列表和元组: 可以看作是普通的数组, 能保存任意数量任意类型的python对象…</p>
<ol>
<li>
列表元素用中括号包裹, 元素的个数及元素的值可以改变.</li>
<li>
元组元素用小括号包裹, 不可以更改, 尽管他们的内容可以, 元组可以看成是只读的列表.  可以使用切片运算得到子集.</li>
</ol>
</li>
<li>
字典: 相当于其他语言中的map, 使用{key: value}的方式表示. 取值的方式和其他语言的map一致.  也可以直接使用map[key] = value的方式为其赋值.</li>
<li>
条件语句:</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">if</span> expression:<br />
&nbsp; &nbsp; path <span style="color: #ff4500;">1</span><br />
<span style="color: #ff7700;font-weight:bold;">elif</span> expression2:<br />
&nbsp; &nbsp; path2<br />
<span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; path3</div></div>
<ol>
<li>
while循环</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">while</span> expression:<br />
&nbsp; &nbsp; process business</div></div>
<ol>
<li>
for循环</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">list</span>|<span style="color: #008000;">tuple</span>|<span style="color: #008000;">map</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> item</div></div>
<ol>
<li>
range(len(list))得到一个list长度范围内的整数list, 方便遍历过程中获取索引值.</li>
<li>
python2.3中增加了enumerate(), 可以通过它遍历list, 同时得到索引和值</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">for</span> index<span style="color: #66cc66;">,</span> data <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span><span style="color: #008000;">list</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> index<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;:&quot;</span><span style="color: #66cc66;">,</span> data<span style="color: #66cc66;">,</span></div></div>
<ol>
<li>
列表解析:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sqdEvens <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>x ** <span style="color: #ff4500;">2</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> x % <span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span></div></div>
<p>, 获取一个序列, 该序列是0-8的数字中所有x%2为0(false)的x的平方</li>
</ol>
<ol>
<li>
文件和内建函数:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">open()</div></div>
<p>,</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">file()</div></div>
<ol>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">handle <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>file_name<span style="color: #66cc66;">,</span> access_mode <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span></div></div>
<p>,<br />
只读方式打开文件, 得到的句柄是handle..该方法如果没有提供access_mode, 默认是r</li>
</ol>
</li>
<li>
异常处理:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">raise</div></div>
<p>可以故意引发异常</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># process</span><br />
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span><span style="color: #66cc66;">,</span> e:<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># error process</span></div></div>
<ol>
<li>
函数: 如果函数中没有return语句, 自动返回None对象</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> function_name<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>arguments<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #483d8b;">&quot;optional document string&quot;</span><br />
&nbsp; &nbsp; function_suite</div></div>
<ol>
<li>
python的函数调用中参数是引用传递</li>
<li>
可以在定义函数的时候, 在参数列表中通过=设置参数的默认值.</li>
</ol>
<ol>
<li>
类:</p>
<ol>
<li>
定义:</li>
</ol>
</li>
</ol>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> class_name:<br />
&nbsp; &nbsp; static_variable_name <span style="color: #66cc66;">=</span> value<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#91;</span>arguments<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; //operation<br />
&nbsp; &nbsp; &nbsp; &nbsp; //<span style="color: #008000;">self</span> <span style="color: #ff7700;font-weight:bold;">in</span> here <span style="color: #ff7700;font-weight:bold;">is</span> the reference <span style="color: #ff7700;font-weight:bold;">for</span> this <span style="color: #ff7700;font-weight:bold;">class</span> instance<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> general_method_name<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#91;</span>arguments<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; //operation<br />
&nbsp; &nbsp; &nbsp; &nbsp; //<span style="color: #008000;">self</span> <span style="color: #ff7700;font-weight:bold;">is</span> the <span style="color: #ff7700;font-weight:bold;">class</span> instance<br />
&nbsp; &nbsp; &nbsp; &nbsp; //<span style="color: #ff7700;font-weight:bold;">if</span> you want to use <span style="color: #ff7700;font-weight:bold;">class</span> variable<span style="color: #66cc66;">,</span> please use like <span style="color: #008000;">self</span>.__class__.__name__</div></div>
<ol>
<li>
实例化:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">instance = class_name([arguments, …]);</div></div>
</li>
</ol>
<ol>
<li>
模块: 不带.py后缀名的文件名…一个模块创建之后, 可以使用import导入这个模块使用.</p>
<ol>
<li>
访问模块内的函数或变量:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;module_name.function() | module_name.variable | module_name.class_name</div></div>
</li>
<li>
sys模块概览</p>
<ol>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Hello World!<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span> &nbsp;//使用<span style="color: #dc143c;">sys</span>模块的标准输出</div></div>
</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #dc143c;">sys</span>.<span style="color: #dc143c;">platform</span> &nbsp;//返回系统的标记</div></div>
</li>
<li>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #dc143c;">sys</span>.<span style="color: black;">version</span> &nbsp;//返回系统的版本</div></div>
</li>
</ol>
</li>
</ol>
</li>
<li>
<div>PEP: 一个PEP就是一个python增强提案(python enhancement proposal), 是在新版python中增加新特性的方式…索引网址是: http://python.org/dev/peps</div>
</li>
<li>
一些常用函数</p>
<ol>
<li>
dir([obj])  显示对象的属性, 如果没有提供参数, 显示全局变量的名字</li>
<li>
help([obj])  显示对象的文档, 如果没有参数, 进入交互式帮助</li>
<li>
int(obj)  将一个对象转换为整数</li>
<li>
len(obj)  返回对象的长度</li>
<li>
open(file_name, mode)  以mode(r|w|a…)方式打开一个文件</li>
<li>
range([[start, ]stop[, step]])  返回一个整数列表…结束值是stop-1, step默认是1</li>
<li>
raw_input(str)  提示str等待用户输入</li>
<li>
str(obj)  将一个对象转换为字符串</li>
<li>
type(obj)  返回对象的类型…返回值本身是一个type对象</li>
<li>
sum(iterable[, start=0])  可以对纯数值的list|tuple|map进行求和操作..</li>
<li>
<div>dir([object])  如果没有参数获得当前脚本scope内定义的对象, 如果有参数, 返回该对象内部定义的对象, 如果该对象有一个__dir__方法, 该方法将被调用, 并且必须返回属性的列表…这就允许通过自定义__getattr__()或__getattribute__()方法的方式实现dir的自定义显示属性列表….如果没有指定参数, 是根据该对象的__dict__内存字典的最佳聚合信息显示的..</div>
</li>
<li>
type([object])  参数为空显示&lt;type &#8216;type&#8217;&gt;, 参数不为空显示该对象的类型</li>
<li>
type(name, bases, dict)  通过名称, 基类, 内存字典动态创建一个类型</li>
<li>
object__name.__doc__  查看该对象的文档字符串</li>
<li>
__doc__ 对象的文档字符串, 该文档字符串在定义对象时写在对象语句块中第一句, 使用单纯的字符串的方式表示</li>
<li>
sys.exit()  退出python解释器</li>
<li>
append(Object)  给list添加一个元素</li>
<li>
os.linesep 返回的是系统换行符…不同的系统换行符是不同的, 使用linesep可以提高代码跨平台性</li>
<li>
string_variable_name.strip([chars])  脱离, 滤去字符串中的某些字符, 如果没有参数返回原字符串</li>
</ol>
</li>
<li>
数值按进制分为:</p>
<ol>
<li>
二进制: 0b101010</li>
<li>
八进制: 07167</li>
<li>
十进制: 98767</li>
<li>
十六进制: 0xf2134</li>
</ol>
</li>
</ol>
<hr /><h2>Related posts:</h2><ul><li><a href="http://tossp.com/python-study-notes-7.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(7章)">PyThon学习笔记(7章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

映射和集合类型(chapter7)

	
字典使用keys()获得键的列表, values()获得值的列表, items()获得包含key-&gt;value对的元组的列表
	
字典的创建和赋值

	
dict = {key: value}
	
dict = dict((key, value), (key,</li><li><a href="http://tossp.com/tcp-ip-detailed-explanation-study-notes-14.html" rel="bookmark" title="Permanent Link: TCP/IP详解学习笔记(14)">TCP/IP详解学习笔记(14)</a><br />终于写到了这一篇,这是TCP协议的最后一个部分，讲述了TCP的一些新的特性（在现在看来都是老特征了），包括路径MTU发现和时间戳选项等等。在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是

    路径MTU发现。
    窗口扩大选项和时间戳。
 </li><li><a href="http://tossp.com/python-study-notes-3-chapters.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(3章)">PyThon学习笔记(3章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
Python基础(chapter3)

	
setence and syntax语句和语法

	
#为注释符号
	
n是标准行分隔符, 通常一个语句一行
	
反斜线表示下一行继续, 用来将单条语句放入多行…尽量使用括号代替
	
分号;表示将两个语句连接在一行中…不提倡
	
冒号:表示将代码块的头和体分开
	
语句(代码块)用缩进块方式体现: 同一个代码组的代码必须严格左对齐..由于不同的editor制表符宽度不一, 为了使代码跨平台, 推荐使用4个空格缩进
	
不同缩进深度分隔不同的代码块
	
python文件以模块的形式组织: 模块以磁盘文件的形式存在, 不应该让某个模块充斥的太大


	
赋值

	
赋值语句没有返回值,</li><li><a href="http://tossp.com/python-study-notes-chapter-5.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(5章)">PyThon学习笔记(5章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢

数字(chapter5)

	
支持的数字类型: 整型, 长整型, 布尔型, 双精度浮点型, 十进制浮点型和复数
	
整型

	
布尔型  包含True和False两个值的整型
	
标准整数类型  0x表示十六进制,</li><li><a href="http://tossp.com/python-study-notes-chapter-4.html" rel="bookmark" title="Permanent Link: PyThon学习笔记(4章)">PyThon学习笔记(4章)</a><br />首先要说明，这套笔记不是我整理

有朋友知道原文出去麻烦告知一声，谢谢
python对象(chapter4)

	
python对象有三个特征: 身份和类型是只读的, 如果对象支持不支持更新操作, 那么值也就是只读的.

	
身份: 唯一的身份标识, 可以使用内建函数id()得到, 可以看作是对象的内存地址…
	
类型: 对象的类型决定该对象保存什么类型的值, 可以进行什么操作, 遵循什么规则.,</li></ul><hr /><small>Copyright &copy; 2005-2010 砼砼's Blog, content license.<br /> (Digital Fingerprint:<br /> 005fc134769e47b97a8ca2738c071bab)</small><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1" color="#105F94" style="display: block !important; padding: 20px 0 5px !important;">砼砼猜你喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="PyThon学习笔记(4章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-4.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13915065.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(4章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(5章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-5.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914951.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(5章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(3章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-3-chapters.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2012/01/13/13914844.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(3章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(7章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-7.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/12056530.jpg" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(7章)</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #aaaaaa !important;">
                    <a target="_blank" title="PyThon学习笔记(6章)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect?url=http%3A%2F%2Ftossp.com%2Fpython-study-notes-chapter-6.html&from=http%3A%2F%2Ftossp.com%2Fpython-study-notes.html">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #aaaaaa !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/11/26/11485341.png" width="96px" height="96px" /><br />
                        <font size="-1"  style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">PyThon学习笔记(6章)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://tossp.com/python-study-notes.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

