{"id":819,"date":"2021-12-13T13:08:00","date_gmt":"2021-12-13T13:08:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=819"},"modified":"2021-12-13T13:08:00","modified_gmt":"2021-12-13T13:08:00","slug":"819","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/12\/13\/819\/","title":{"rendered":"\u5173\u4e8ePython\u7684\u95ee\u9898\u4ecegithub\u7b14\u8bb0"},"content":{"rendered":"<p><!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again --><\/p>\n<p><strong>Table of Contents<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"#python\">Python\u8bed\u8a00\u7279\u6027<\/a><\/p>\n<ul>\n<li><a href=\"#1-python\">1 Python\u7684\u51fd\u6570\u53c2\u6570\u4f20\u9012<\/a><\/li>\n<li><a href=\"#2-pythonmetaclass\">2 Python\u4e2d\u7684\u5143\u7c7b(metaclass)<\/a><\/li>\n<li><a href=\"#3-staticmethodclassmethod\">3 @staticmethod\u548c@classmethod<\/a><\/li>\n<li><a href=\"#4-\">4 \u7c7b\u53d8\u91cf\u548c\u5b9e\u4f8b\u53d8\u91cf<\/a><\/li>\n<li><a href=\"#5-python\">5 Python\u81ea\u7701<\/a><\/li>\n<li><a href=\"#6-\">6 \u5b57\u5178\u63a8\u5bfc\u5f0f<\/a><\/li>\n<li><a href=\"#7-python\">7 Python\u4e2d\u5355\u4e0b\u5212\u7ebf\u548c\u53cc\u4e0b\u5212\u7ebf<\/a><\/li>\n<li><a href=\"#8-format\">8 \u5b57\u7b26\u4e32\u683c\u5f0f\u5316:%\u548c.format<\/a><\/li>\n<li><a href=\"#9-\">9 \u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668<\/a><\/li>\n<li><a href=\"#10-args-and-kwargs\">10 <code>*args<\/code> and <code>**kwargs<\/code><\/a><\/li>\n<li><a href=\"#11-aop\">11 \u9762\u5411\u5207\u9762\u7f16\u7a0bAOP\u548c\u88c5\u9970\u5668<\/a><\/li>\n<li><a href=\"#12-\">12 \u9e2d\u5b50\u7c7b\u578b<\/a><\/li>\n<li><a href=\"#13-python\">13 Python\u4e2d\u91cd\u8f7d<\/a><\/li>\n<li><a href=\"#14-\">14 \u65b0\u5f0f\u7c7b\u548c\u65e7\u5f0f\u7c7b<\/a><\/li>\n<li><a href=\"#15-newinit\">15 <code>__new__<\/code>\u548c<code>__init__<\/code>\u7684\u533a\u522b<\/a><\/li>\n<li>\n<p><a href=\"#16-\">16 \u5355\u4f8b\u6a21\u5f0f<\/a><\/p>\n<ul>\n<li><a href=\"#1-new\">1 \u4f7f\u7528<code>__new__<\/code>\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"#2-\">2 \u5171\u4eab\u5c5e\u6027<\/a><\/li>\n<li><a href=\"#3-\">3 \u88c5\u9970\u5668\u7248\u672c<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#17-python\">17 Python\u4e2d\u7684\u4f5c\u7528\u57df<\/a><\/li>\n<li><a href=\"#18-gil\">18 GIL\u7ebf\u7a0b\u5168\u5c40\u9501<\/a><\/li>\n<li><a href=\"#19-\">19 \u534f\u7a0b<\/a><\/li>\n<li><a href=\"#20-\">20 \u95ed\u5305<\/a><\/li>\n<li><a href=\"#21-lambda\">21 lambda\u51fd\u6570<\/a><\/li>\n<li><a href=\"#22-python\">22 Python\u51fd\u6570\u5f0f\u7f16\u7a0b<\/a><\/li>\n<li><a href=\"#23-python\">23 Python\u91cc\u7684\u62f7\u8d1d<\/a><\/li>\n<li>\n<p><a href=\"#24-python\">24 Python\u5783\u573e\u56de\u6536\u673a\u5236<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u5f15\u7528\u8ba1\u6570<\/a><\/li>\n<li><a href=\"#2--\">2 \u6807\u8bb0-\u6e05\u9664\u673a\u5236<\/a><\/li>\n<li><a href=\"#3-\">3 \u5206\u4ee3\u6280\u672f<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#25-pythonlist\">25 Python\u7684List<\/a><\/li>\n<li><a href=\"#26-pythonis\">26 Python\u7684is<\/a><\/li>\n<li><a href=\"#27-readreadlinereadlines\">27 read,readline\u548creadlines<\/a><\/li>\n<li><a href=\"#28-python23\">28 Python2\u548c3\u7684\u533a\u522b<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#\">\u64cd\u4f5c\u7cfb\u7edf<\/a><\/p>\n<ul>\n<li><a href=\"#1-selectpollepoll\">1 select,poll\u548cepoll<\/a><\/li>\n<li><a href=\"#2-\">2 \u8c03\u5ea6\u7b97\u6cd5<\/a><\/li>\n<li><a href=\"#3-\">3 \u6b7b\u9501<\/a><\/li>\n<li>\n<p><a href=\"#4-\">4 \u7a0b\u5e8f\u7f16\u8bd1\u4e0e\u94fe\u63a5<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u9884\u5904\u7406<\/a><\/li>\n<li><a href=\"#2-\">2 \u7f16\u8bd1<\/a><\/li>\n<li><a href=\"#3-\">3 \u6c47\u7f16<\/a><\/li>\n<li><a href=\"#4-\">4 \u94fe\u63a5<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#5-\">5 \u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5<\/a><\/li>\n<li><a href=\"#6-\">6 \u865a\u62df\u5185\u5b58\u6280\u672f<\/a><\/li>\n<li>\n<p><a href=\"#7-\">7 \u5206\u9875\u548c\u5206\u6bb5<\/a><\/p>\n<ul>\n<li><a href=\"#\">\u5206\u9875\u4e0e\u5206\u6bb5\u7684\u4e3b\u8981\u533a\u522b<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#8-\">8 \u9875\u9762\u7f6e\u6362\u7b97\u6cd5<\/a><\/li>\n<li><a href=\"#9-\">9 \u8fb9\u6cbf\u89e6\u53d1\u548c\u6c34\u5e73\u89e6\u53d1<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#\">\u6570\u636e\u5e93<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u4e8b\u52a1<\/a><\/li>\n<li><a href=\"#2-\">2 \u6570\u636e\u5e93\u7d22\u5f15<\/a><\/li>\n<li><a href=\"#3-redis\">3 Redis\u539f\u7406<\/a><\/li>\n<li><a href=\"#4-\">4 \u4e50\u89c2\u9501\u548c\u60b2\u89c2\u9501<\/a><\/li>\n<li><a href=\"#5-mvcc\">5 MVCC<\/a><\/li>\n<li><a href=\"#6-myisaminnodb\">6 MyISAM\u548cInnoDB<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#\">\u7f51\u7edc<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u4e09\u6b21\u63e1\u624b<\/a><\/li>\n<li><a href=\"#2-\">2 \u56db\u6b21\u6325\u624b<\/a><\/li>\n<li><a href=\"#3-arp\">3 ARP\u534f\u8bae<\/a><\/li>\n<li><a href=\"#4-urlliburllib2\">4 urllib\u548curllib2\u7684\u533a\u522b<\/a><\/li>\n<li><a href=\"#5-postget\">5 Post\u548cGet<\/a><\/li>\n<li><a href=\"#6-cookiesession\">6 Cookie\u548cSession<\/a><\/li>\n<li><a href=\"#7-apachenginx\">7 apache\u548cnginx\u7684\u533a\u522b<\/a><\/li>\n<li><a href=\"#8-\">8 \u7f51\u7ad9\u7528\u6237\u5bc6\u7801\u4fdd\u5b58<\/a><\/li>\n<li><a href=\"#9-httphttps\">9 HTTP\u548cHTTPS<\/a><\/li>\n<li><a href=\"#10-xsrfxss\">10 XSRF\u548cXSS<\/a><\/li>\n<li><a href=\"#11--idempotence\">11 \u5e42\u7b49 Idempotence<\/a><\/li>\n<li><a href=\"#12-restfulsoaprpc\">12 RESTful\u67b6\u6784(SOAP,RPC)<\/a><\/li>\n<li><a href=\"#13-soap\">13 SOAP<\/a><\/li>\n<li><a href=\"#14-rpc\">14 RPC<\/a><\/li>\n<li><a href=\"#15-cgiwsgi\">15 CGI\u548cWSGI<\/a><\/li>\n<li><a href=\"#16-\">16 \u4e2d\u95f4\u4eba\u653b\u51fb<\/a><\/li>\n<li><a href=\"#17-c10k\">17 c10k\u95ee\u9898<\/a><\/li>\n<li><a href=\"#18-socket\">18 socket<\/a><\/li>\n<li><a href=\"#19-\">19 \u6d4f\u89c8\u5668\u7f13\u5b58<\/a><\/li>\n<li><a href=\"#20-http10http11\">20 HTTP1.0\u548cHTTP1.1<\/a><\/li>\n<li><a href=\"#21-ajax\">21 Ajax<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#nix\">*NIX<\/a><\/p>\n<ul>\n<li><a href=\"#unixipc\">unix\u8fdb\u7a0b\u95f4\u901a\u4fe1\u65b9\u5f0f(IPC)<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#\">\u6570\u636e\u7ed3\u6784<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u7ea2\u9ed1\u6811<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\n<p><a href=\"#\">\u7f16\u7a0b\u9898<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u53f0\u9636\u95ee\u9898\/\u6590\u6ce2\u7eb3\u6308<\/a><\/li>\n<li><a href=\"#2-\">2 \u53d8\u6001\u53f0\u9636\u95ee\u9898<\/a><\/li>\n<li><a href=\"#3-\">3 \u77e9\u5f62\u8986\u76d6<\/a><\/li>\n<li><a href=\"#4-\">4 \u6768\u6c0f\u77e9\u9635\u67e5\u627e<\/a><\/li>\n<li><a href=\"#5-\">5 \u53bb\u9664\u5217\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20<\/a><\/li>\n<li><a href=\"#6-\">6 \u94fe\u8868\u6210\u5bf9\u8c03\u6362<\/a><\/li>\n<li>\n<p><a href=\"#7-\">7 \u521b\u5efa\u5b57\u5178\u7684\u65b9\u6cd5<\/a><\/p>\n<ul>\n<li><a href=\"#1-\">1 \u76f4\u63a5\u521b\u5efa<\/a><\/li>\n<li><a href=\"#2-\">2 \u5de5\u5382\u65b9\u6cd5<\/a><\/li>\n<li><a href=\"#3-fromkeys\">3 fromkeys()\u65b9\u6cd5<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#8-\">8 \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u5217\u8868<\/a><\/li>\n<li><a href=\"#9-\">9 \u4ea4\u53c9\u94fe\u8868\u6c42\u4ea4\u70b9<\/a><\/li>\n<li><a href=\"#10-\">10 \u4e8c\u5206\u67e5\u627e<\/a><\/li>\n<li><a href=\"#11-\">11 \u5feb\u6392<\/a><\/li>\n<li><a href=\"#12-\">12 \u627e\u96f6\u95ee\u9898<\/a><\/li>\n<li><a href=\"#13-\">13 \u5e7f\u5ea6\u904d\u5386\u548c\u6df1\u5ea6\u904d\u5386\u4e8c\u53c9\u6811<\/a><\/li>\n<li><a href=\"#14-\">14 \u4e8c\u53c9\u6811\u8282\u70b9<\/a><\/li>\n<li><a href=\"#15-\">15 \u5c42\u6b21\u904d\u5386<\/a><\/li>\n<li><a href=\"#16-\">16 \u6df1\u5ea6\u904d\u5386<\/a><\/li>\n<li><a href=\"#17-\">17 \u524d\u4e2d\u540e\u5e8f\u904d\u5386<\/a><\/li>\n<li><a href=\"#18-\">18 \u6c42\u6700\u5927\u6811\u6df1<\/a><\/li>\n<li><a href=\"#19-\">19 \u6c42\u4e24\u68f5\u6811\u662f\u5426\u76f8\u540c<\/a><\/li>\n<li><a href=\"#20-\">20 \u524d\u5e8f\u4e2d\u5e8f\u6c42\u540e\u5e8f<\/a><\/li>\n<li><a href=\"#21-\">21 \u5355\u94fe\u8868\u9006\u7f6e<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><!-- markdown-toc end --><\/p>\n<h1>Python\u8bed\u8a00\u7279\u6027<\/h1>\n<h2>1 Python\u7684\u51fd\u6570\u53c2\u6570\u4f20\u9012<\/h2>\n<p>\u770b\u4e24\u4e2a\u4f8b\u5b50:<\/p>\n<pre><code class=\"lang-python\">a = 1\ndef fun(a):\n    a = 2\nprint a  # 1<\/code><\/pre>\n<pre><code class=\"lang-python\">a = []\ndef fun(a):\n    a.append(1)\nprint a  # [1]<\/code><\/pre>\n<p>\u6240\u6709\u7684\u53d8\u91cf\u90fd\u53ef\u4ee5\u7406\u89e3\u662f\u5185\u5b58\u4e2d\u4e00\u4e2a\u5bf9\u8c61\u7684\u201c\u5f15\u7528\u201d\uff0c\u6216\u8005\uff0c\u4e5f\u53ef\u4ee5\u770b\u4f3cc\u4e2dvoid*\u7684\u611f\u89c9\u3002<\/p>\n<p>\u8fd9\u91cc\u8bb0\u4f4f\u7684\u662f\u7c7b\u578b\u662f\u5c5e\u4e8e\u5bf9\u8c61\u7684\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u3002\u800c\u5bf9\u8c61\u6709\u4e24\u79cd,\u201c\u53ef\u66f4\u6539\u201d\uff08mutable\uff09\u4e0e\u201c\u4e0d\u53ef\u66f4\u6539\u201d\uff08immutable\uff09\u5bf9\u8c61\u3002\u5728python\u4e2d\uff0cstrings, tuples, \u548cnumbers\u662f\u4e0d\u53ef\u66f4\u6539\u7684\u5bf9\u8c61\uff0c\u800clist,dict\u7b49\u5219\u662f\u53ef\u4ee5\u4fee\u6539\u7684\u5bf9\u8c61\u3002(\u8fd9\u5c31\u662f\u8fd9\u4e2a\u95ee\u9898\u7684\u91cd\u70b9)<\/p>\n<p>\u5f53\u4e00\u4e2a\u5f15\u7528\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u65f6\u5019,\u51fd\u6570\u81ea\u52a8\u590d\u5236\u4e00\u4efd\u5f15\u7528,\u8fd9\u4e2a\u51fd\u6570\u91cc\u7684\u5f15\u7528\u548c\u5916\u8fb9\u7684\u5f15\u7528\u6ca1\u6709\u534a\u6bdb\u5173\u7cfb\u4e86.\u6240\u4ee5\u7b2c\u4e00\u4e2a\u4f8b\u5b50\u91cc\u51fd\u6570\u628a\u5f15\u7528\u6307\u5411\u4e86\u4e00\u4e2a\u4e0d\u53ef\u53d8\u5bf9\u8c61,\u5f53\u51fd\u6570\u8fd4\u56de\u7684\u65f6\u5019,\u5916\u9762\u7684\u5f15\u7528\u6ca1\u534a\u6bdb\u611f\u89c9.\u800c\u7b2c\u4e8c\u4e2a\u4f8b\u5b50\u5c31\u4e0d\u4e00\u6837\u4e86,\u51fd\u6570\u5185\u7684\u5f15\u7528\u6307\u5411\u7684\u662f\u53ef\u53d8\u5bf9\u8c61,\u5bf9\u5b83\u7684\u64cd\u4f5c\u5c31\u548c\u5b9a\u4f4d\u4e86\u6307\u9488\u5730\u5740\u4e00\u6837,\u5728\u5185\u5b58\u91cc\u8fdb\u884c\u4fee\u6539.<\/p>\n<p>\u5982\u679c\u8fd8\u4e0d\u660e\u767d\u7684\u8bdd,\u8fd9\u91cc\u6709\u66f4\u597d\u7684\u89e3\u91ca: <a href=\"http:\/\/stackoverflow.com\/questions\/986006\/how-do-i-pass-a-variable-by-reference\">http:\/\/stackoverflow.com\/questions\/986006\/how-do-i-pass-a-variable-by-reference<\/a><\/p>\n<h2>2 Python\u4e2d\u7684\u5143\u7c7b(metaclass)<\/h2>\n<p>\u8fd9\u4e2a\u975e\u5e38\u7684\u4e0d\u5e38\u7528,\u4f46\u662f\u50cfORM\u8fd9\u79cd\u590d\u6742\u7684\u7ed3\u6784\u8fd8\u662f\u4f1a\u9700\u8981\u7684,\u8be6\u60c5\u8bf7\u770b:<a href=\"http:\/\/stackoverflow.com\/questions\/100003\/what-is-a-metaclass-in-python\">http:\/\/stackoverflow.com\/questions\/100003\/what-is-a-metaclass-in-python<\/a><\/p>\n<h2>3 @staticmethod\u548c@classmethod<\/h2>\n<p>Python\u5176\u5b9e\u67093\u4e2a\u65b9\u6cd5,\u5373\u9759\u6001\u65b9\u6cd5(staticmethod),\u7c7b\u65b9\u6cd5(classmethod)\u548c\u5b9e\u4f8b\u65b9\u6cd5,\u5982\u4e0b:<\/p>\n<pre><code class=\"lang-python\">def foo(x):\n    print \"executing foo(%s)\"%(x)\n\nclass A(object):\n    def foo(self,x):\n        print \"executing foo(%s,%s)\"%(self,x)\n\n    @classmethod\n    def class_foo(cls,x):\n        print \"executing class_foo(%s,%s)\"%(cls,x)\n\n    @staticmethod\n    def static_foo(x):\n        print \"executing static_foo(%s)\"%x\n\na=A()\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u5148\u7406\u89e3\u4e0b\u51fd\u6570\u53c2\u6570\u91cc\u9762\u7684self\u548ccls.\u8fd9\u4e2aself\u548ccls\u662f\u5bf9\u7c7b\u6216\u8005\u5b9e\u4f8b\u7684\u7ed1\u5b9a,\u5bf9\u4e8e\u4e00\u822c\u7684\u51fd\u6570\u6765\u8bf4\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e48\u8c03\u7528<code>foo(x)<\/code>,\u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u6700\u5e38\u7528\u7684,\u5b83\u7684\u5de5\u4f5c\u8ddf\u4efb\u4f55\u4e1c\u897f(\u7c7b,\u5b9e\u4f8b)\u65e0\u5173.\u5bf9\u4e8e\u5b9e\u4f8b\u65b9\u6cd5,\u6211\u4eec\u77e5\u9053\u5728\u7c7b\u91cc\u6bcf\u6b21\u5b9a\u4e49\u65b9\u6cd5\u7684\u65f6\u5019\u90fd\u9700\u8981\u7ed1\u5b9a\u8fd9\u4e2a\u5b9e\u4f8b,\u5c31\u662f<code>foo(self, x)<\/code>,\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a\u5462?\u56e0\u4e3a\u5b9e\u4f8b\u65b9\u6cd5\u7684\u8c03\u7528\u79bb\u4e0d\u5f00\u5b9e\u4f8b,\u6211\u4eec\u9700\u8981\u628a\u5b9e\u4f8b\u81ea\u5df1\u4f20\u7ed9\u51fd\u6570,\u8c03\u7528\u7684\u65f6\u5019\u662f\u8fd9\u6837\u7684<code>a.foo(x)<\/code>(\u5176\u5b9e\u662f<code>foo(a, x)<\/code>).\u7c7b\u65b9\u6cd5\u4e00\u6837,\u53ea\u4e0d\u8fc7\u5b83\u4f20\u9012\u7684\u662f\u7c7b\u800c\u4e0d\u662f\u5b9e\u4f8b,<code>A.class_foo(x)<\/code>.\u6ce8\u610f\u8fd9\u91cc\u7684self\u548ccls\u53ef\u4ee5\u66ff\u6362\u522b\u7684\u53c2\u6570,\u4f46\u662fpython\u7684\u7ea6\u5b9a\u662f\u8fd9\u4fe9,\u8fd8\u662f\u4e0d\u8981\u6539\u7684\u597d.<\/p>\n<p>\u5bf9\u4e8e\u9759\u6001\u65b9\u6cd5\u5176\u5b9e\u548c\u666e\u901a\u7684\u65b9\u6cd5\u4e00\u6837,\u4e0d\u9700\u8981\u5bf9\u8c01\u8fdb\u884c\u7ed1\u5b9a,\u552f\u4e00\u7684\u533a\u522b\u662f\u8c03\u7528\u7684\u65f6\u5019\u9700\u8981\u4f7f\u7528<code>a.static_foo(x)<\/code>\u6216\u8005<code>A.static_foo(x)<\/code>\u6765\u8c03\u7528.<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\\<\/th>\n<th align=\"left\">\u5b9e\u4f8b\u65b9\u6cd5<\/th>\n<th align=\"left\">\u7c7b\u65b9\u6cd5<\/th>\n<th align=\"left\">\u9759\u6001\u65b9\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">a = A()<\/td>\n<td align=\"left\">a.foo(x)<\/td>\n<td align=\"left\">a.class_foo(x)<\/td>\n<td align=\"left\">a.static_foo(x)<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">A<\/td>\n<td align=\"left\">\u4e0d\u53ef\u7528<\/td>\n<td align=\"left\">A.class_foo(x)<\/td>\n<td align=\"left\">A.static_foo(x)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u66f4\u591a\u5173\u4e8e\u8fd9\u4e2a\u95ee\u9898:<a href=\"http:\/\/stackoverflow.com\/questions\/136097\/what-is-the-difference-between-staticmethod-and-classmethod-in-python\">http:\/\/stackoverflow.com\/questions\/136097\/what-is-the-difference-between-staticmethod-and-classmethod-in-python<\/a><\/p>\n<h2>4 \u7c7b\u53d8\u91cf\u548c\u5b9e\u4f8b\u53d8\u91cf<\/h2>\n<pre><code class=\"lang-python\">class Person:\n    name=\"aaa\"\n\np1=Person()\np2=Person()\np1.name=\"bbb\"\nprint p1.name  # bbb\nprint p2.name  # aaa\nprint Person.name  # aaa<\/code><\/pre>\n<p>\u7c7b\u53d8\u91cf\u5c31\u662f\u4f9b\u7c7b\u4f7f\u7528\u7684\u53d8\u91cf,\u5b9e\u4f8b\u53d8\u91cf\u5c31\u662f\u4f9b\u5b9e\u4f8b\u4f7f\u7528\u7684.<\/p>\n<p>\u8fd9\u91cc<code>p1.name=<\/code>bbb<code>\u662f\u5b9e\u4f8b\u8c03\u7528\u4e86\u7c7b\u53d8\u91cf,\u8fd9\u5176\u5b9e\u548c\u4e0a\u9762\u7b2c\u4e00\u4e2a\u95ee\u9898\u4e00\u6837,\u5c31\u662f\u51fd\u6570\u4f20\u53c2\u7684\u95ee\u9898,\"p1.name\"\u4e00\u5f00\u59cb\u662f\u6307\u5411\u7684\u7c7b\u53d8\u91cf\"name=\"aaa<\/code>,\u4f46\u662f\u5728\u5b9e\u4f8b\u7684\u4f5c\u7528\u57df\u91cc\u628a\u7c7b\u53d8\u91cf\u7684\u5f15\u7528\u6539\u53d8\u4e86,\u5c31\u53d8\u6210\u4e86\u4e00\u4e2a\u5b9e\u4f8b\u53d8\u91cf,self.name\u4e0d\u518d\u5f15\u7528Person\u7684\u7c7b\u53d8\u91cfname\u4e86.<\/p>\n<p>\u53ef\u4ee5\u770b\u770b\u4e0b\u9762\u7684\u4f8b\u5b50:<\/p>\n<pre><code class=\"lang-python\">class Person:\n    name=[]\n\np1=Person()\np2=Person()\np1.name.append(1)\nprint p1.name  # [1]\nprint p2.name  # [1]\nprint Person.name  # [1]<\/code><\/pre>\n<p>\u53c2\u8003:<a href=\"http:\/\/stackoverflow.com\/questions\/6470428\/catch-multiple-exceptions-in-one-line-except-block\">http:\/\/stackoverflow.com\/questions\/6470428\/catch-multiple-exceptions-in-one-line-except-block<\/a><\/p>\n<h2>5 Python\u81ea\u7701<\/h2>\n<p>\u8fd9\u4e2a\u4e5f\u662fpython\u5f6a\u608d\u7684\u7279\u6027.<\/p>\n<p>\u81ea\u7701\u5c31\u662f\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u8a00\u6240\u5199\u7684\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6,\u6240\u80fd\u77e5\u9053\u5bf9\u8c61\u7684\u7c7b\u578b.\u7b80\u5355\u4e00\u53e5\u5c31\u662f\u8fd0\u884c\u65f6\u80fd\u591f\u83b7\u5f97\u5bf9\u8c61\u7684\u7c7b\u578b.\u6bd4\u5982type(),dir(),getattr(),hasattr(),isinstance().<\/p>\n<h2>6 \u5b57\u5178\u63a8\u5bfc\u5f0f<\/h2>\n<p>\u53ef\u80fd\u4f60\u89c1\u8fc7\u5217\u8868\u63a8\u5bfc\u65f6,\u5374\u6ca1\u6709\u89c1\u8fc7\u5b57\u5178\u63a8\u5bfc\u5f0f,\u57282.7\u4e2d\u624d\u52a0\u5165\u7684:<\/p>\n<pre><code class=\"lang-python\">d = {key: value for (key, value) in iterable}<\/code><\/pre>\n<h2>7 Python\u4e2d\u5355\u4e0b\u5212\u7ebf\u548c\u53cc\u4e0b\u5212\u7ebf<\/h2>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; class MyClass():\n...     def __init__(self):\n...             self.__superprivate = \"Hello\"\n...             self._semiprivate = \", world!\"\n...\n&gt;&gt;&gt; mc = MyClass()\n&gt;&gt;&gt; print mc.__superprivate\nTraceback (most recent call last):\n  File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;\nAttributeError: myClass instance has no attribute '__superprivate'\n&gt;&gt;&gt; print mc._semiprivate\n, world!\n&gt;&gt;&gt; print mc.__dict__\n{'_MyClass__superprivate': 'Hello', '_semiprivate': ', world!'}<\/code><\/pre>\n<p><code>__foo__<\/code>:\u4e00\u79cd\u7ea6\u5b9a,Python\u5185\u90e8\u7684\u540d\u5b57,\u7528\u6765\u533a\u522b\u5176\u4ed6\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u547d\u540d,\u4ee5\u9632\u51b2\u7a81.<\/p>\n<p><code>_foo<\/code>:\u4e00\u79cd\u7ea6\u5b9a,\u7528\u6765\u6307\u5b9a\u53d8\u91cf\u79c1\u6709.\u7a0b\u5e8f\u5458\u7528\u6765\u6307\u5b9a\u79c1\u6709\u53d8\u91cf\u7684\u4e00\u79cd\u65b9\u5f0f.<\/p>\n<p><code>__foo<\/code>:\u8fd9\u4e2a\u6709\u771f\u6b63\u7684\u610f\u4e49:\u89e3\u6790\u5668\u7528<code>_classname__foo<\/code>\u6765\u4ee3\u66ff\u8fd9\u4e2a\u540d\u5b57,\u4ee5\u533a\u522b\u548c\u5176\u4ed6\u7c7b\u76f8\u540c\u7684\u547d\u540d.<\/p>\n<p>\u8be6\u60c5\u89c1:<a href=\"http:\/\/stackoverflow.com\/questions\/1301346\/the-meaning-of-a-single-and-a-double-underscore-before-an-object-name-in-python\">http:\/\/stackoverflow.com\/questions\/1301346\/the-meaning-of-a-single-and-a-double-underscore-before-an-object-name-in-python<\/a><\/p>\n<p>\u6216\u8005: <a href=\"http:\/\/www.zhihu.com\/question\/19754941\">http:\/\/www.zhihu.com\/question\/19754941<\/a><\/p>\n<h2>8 \u5b57\u7b26\u4e32\u683c\u5f0f\u5316:%\u548c.format<\/h2>\n<p>.format\u5728\u8bb8\u591a\u65b9\u9762\u770b\u8d77\u6765\u66f4\u4fbf\u5229.\u5bf9\u4e8e<code>%<\/code>\u6700\u70e6\u4eba\u7684\u662f\u5b83\u65e0\u6cd5\u540c\u65f6\u4f20\u9012\u4e00\u4e2a\u53d8\u91cf\u548c\u5143\u7ec4.\u4f60\u53ef\u80fd\u4f1a\u60f3\u4e0b\u9762\u7684\u4ee3\u7801\u4e0d\u4f1a\u6709\u4ec0\u4e48\u95ee\u9898:<\/p>\n<pre><code>\"hi there %s\" % name<\/code><\/pre>\n<p>\u4f46\u662f,\u5982\u679cname\u6070\u597d\u662f(1,2,3),\u5b83\u5c06\u4f1a\u629b\u51fa\u4e00\u4e2aTypeError\u5f02\u5e38.\u4e3a\u4e86\u4fdd\u8bc1\u5b83\u603b\u662f\u6b63\u786e\u7684,\u4f60\u5fc5\u987b\u8fd9\u6837\u505a:<\/p>\n<pre><code>\"hi there %s\" % (name,)   # \u63d0\u4f9b\u4e00\u4e2a\u5355\u5143\u7d20\u7684\u6570\u7ec4\u800c\u4e0d\u662f\u4e00\u4e2a\u53c2\u6570<\/code><\/pre>\n<p>\u4f46\u662f\u6709\u70b9\u4e11..format\u5c31\u6ca1\u6709\u8fd9\u4e9b\u95ee\u9898.\u4f60\u7ed9\u7684\u7b2c\u4e8c\u4e2a\u95ee\u9898\u4e5f\u662f\u8fd9\u6837,.format\u597d\u770b\u591a\u4e86.<\/p>\n<p>\u4f60\u4e3a\u4ec0\u4e48\u4e0d\u7528\u5b83?<\/p>\n<ul>\n<li>\u4e0d\u77e5\u9053\u5b83(\u5728\u8bfb\u8fd9\u4e2a\u4e4b\u524d)<\/li>\n<li>\u4e3a\u4e86\u548cPython2.5\u517c\u5bb9(\u8b6c\u5982logging\u5e93\u5efa\u8bae\u4f7f\u7528<code>%<\/code>(<a href=\"https:\/\/github.com\/taizilongxu\/interview_python\/issues\/4\">issue #4<\/a>))<\/li>\n<\/ul>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/5082452\/python-string-formatting-vs-format\">http:\/\/stackoverflow.com\/questions\/5082452\/python-string-formatting-vs-format<\/a><\/p>\n<h2>9 \u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668<\/h2>\n<p>\u8fd9\u4e2a\u662fstackoverflow\u91ccpython\u6392\u540d\u7b2c\u4e00\u7684\u95ee\u9898,\u503c\u5f97\u4e00\u770b: <a href=\"http:\/\/stackoverflow.com\/questions\/231767\/what-does-the-yield-keyword-do-in-python\">http:\/\/stackoverflow.com\/questions\/231767\/what-does-the-yield-keyword-do-in-python<\/a><\/p>\n<p>\u8fd9\u662f\u4e2d\u6587\u7248: <a href=\"http:\/\/taizilongxu.gitbooks.io\/stackoverflow-about-python\/content\/1\/README.html\">http:\/\/taizilongxu.gitbooks.io\/stackoverflow-about-python\/content\/1\/README.html<\/a><\/p>\n<h2>10 <code>*args<\/code> and <code>**kwargs<\/code><\/h2>\n<p>\u7528<code>*args<\/code>\u548c<code>**kwargs<\/code>\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u5e76\u6ca1\u6709\u5f3a\u5236\u4f7f\u7528\u5b83\u4eec.<\/p>\n<p>\u5f53\u4f60\u4e0d\u786e\u5b9a\u4f60\u7684\u51fd\u6570\u91cc\u5c06\u8981\u4f20\u9012\u591a\u5c11\u53c2\u6570\u65f6\u4f60\u53ef\u4ee5\u7528<code>*args<\/code>.\u4f8b\u5982,\u5b83\u53ef\u4ee5\u4f20\u9012\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570:<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; def print_everything(*args):\n        for count, thing in enumerate(args):\n...         print '{0}. {1}'.format(count, thing)\n...\n&gt;&gt;&gt; print_everything('apple', 'banana', 'cabbage')\n0. apple\n1. banana\n2. cabbage<\/code><\/pre>\n<p>\u76f8\u4f3c\u7684,<code>**kwargs<\/code>\u5141\u8bb8\u4f60\u4f7f\u7528\u6ca1\u6709\u4e8b\u5148\u5b9a\u4e49\u7684\u53c2\u6570\u540d:<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; def table_things(**kwargs):\n...     for name, value in kwargs.items():\n...         print '{0} = {1}'.format(name, value)\n...\n&gt;&gt;&gt; table_things(apple = 'fruit', cabbage = 'vegetable')\ncabbage = vegetable\napple = fruit<\/code><\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u6df7\u7740\u7528.\u547d\u540d\u53c2\u6570\u9996\u5148\u83b7\u5f97\u53c2\u6570\u503c\u7136\u540e\u6240\u6709\u7684\u5176\u4ed6\u53c2\u6570\u90fd\u4f20\u9012\u7ed9<code>*args<\/code>\u548c<code>**kwargs<\/code>.\u547d\u540d\u53c2\u6570\u5728\u5217\u8868\u7684\u6700\u524d\u7aef.\u4f8b\u5982:<\/p>\n<pre><code>def table_things(titlestring, **kwargs)<\/code><\/pre>\n<p><code>*args<\/code>\u548c<code>**kwargs<\/code>\u53ef\u4ee5\u540c\u65f6\u5728\u51fd\u6570\u7684\u5b9a\u4e49\u4e2d,\u4f46\u662f<code>*args<\/code>\u5fc5\u987b\u5728<code>**kwargs<\/code>\u524d\u9762.<\/p>\n<p>\u5f53\u8c03\u7528\u51fd\u6570\u65f6\u4f60\u4e5f\u53ef\u4ee5\u7528<code>*<\/code>\u548c<code>**<\/code>\u8bed\u6cd5.\u4f8b\u5982:<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; def print_three_things(a, b, c):\n...     print 'a = {0}, b = {1}, c = {2}'.format(a,b,c)\n...\n&gt;&gt;&gt; mylist = ['aardvark', 'baboon', 'cat']\n&gt;&gt;&gt; print_three_things(*mylist)\n\na = aardvark, b = baboon, c = cat<\/code><\/pre>\n<p>\u5c31\u50cf\u4f60\u770b\u5230\u7684\u4e00\u6837,\u5b83\u53ef\u4ee5\u4f20\u9012\u5217\u8868(\u6216\u8005\u5143\u7ec4)\u7684\u6bcf\u4e00\u9879\u5e76\u628a\u5b83\u4eec\u89e3\u5305.\u6ce8\u610f\u5fc5\u987b\u4e0e\u5b83\u4eec\u5728\u51fd\u6570\u91cc\u7684\u53c2\u6570\u76f8\u543b\u5408.\u5f53\u7136,\u4f60\u4e5f\u53ef\u4ee5\u5728\u51fd\u6570\u5b9a\u4e49\u6216\u8005\u51fd\u6570\u8c03\u7528\u65f6\u7528*.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/3394835\/args-and-kwargs\">http:\/\/stackoverflow.com\/questions\/3394835\/args-and-kwargs<\/a><\/p>\n<h2>11 \u9762\u5411\u5207\u9762\u7f16\u7a0bAOP\u548c\u88c5\u9970\u5668<\/h2>\n<p>\u8fd9\u4e2aAOP\u4e00\u542c\u8d77\u6765\u6709\u70b9\u61f5,\u540c\u5b66\u9762\u963f\u91cc\u7684\u65f6\u5019\u5c31\u88ab\u95ee\u61f5\u4e86...<\/p>\n<p>\u88c5\u9970\u5668\u662f\u4e00\u4e2a\u5f88\u8457\u540d\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u7ecf\u5e38\u88ab\u7528\u4e8e\u6709\u5207\u9762\u9700\u6c42\u7684\u573a\u666f\uff0c\u8f83\u4e3a\u7ecf\u5178\u7684\u6709\u63d2\u5165\u65e5\u5fd7\u3001\u6027\u80fd\u6d4b\u8bd5\u3001\u4e8b\u52a1\u5904\u7406\u7b49\u3002\u88c5\u9970\u5668\u662f\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u7684\u7edd\u4f73\u8bbe\u8ba1\uff0c\u6709\u4e86\u88c5\u9970\u5668\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u62bd\u79bb\u51fa\u5927\u91cf\u51fd\u6570\u4e2d\u4e0e\u51fd\u6570\u529f\u80fd\u672c\u8eab\u65e0\u5173\u7684\u96f7\u540c\u4ee3\u7801\u5e76\u7ee7\u7eed\u91cd\u7528\u3002\u6982\u62ec\u7684\u8bb2\uff0c<strong>\u88c5\u9970\u5668\u7684\u4f5c\u7528\u5c31\u662f\u4e3a\u5df2\u7ecf\u5b58\u5728\u7684\u5bf9\u8c61\u6dfb\u52a0\u989d\u5916\u7684\u529f\u80fd\u3002<\/strong><\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u6bd4\u8f83\u5927,\u63a8\u8350: <a href=\"http:\/\/stackoverflow.com\/questions\/739654\/how-can-i-make-a-chain-of-function-decorators-in-python\">http:\/\/stackoverflow.com\/questions\/739654\/how-can-i-make-a-chain-of-function-decorators-in-python<\/a><\/p>\n<p>\u4e2d\u6587: <a href=\"http:\/\/taizilongxu.gitbooks.io\/stackoverflow-about-python\/content\/3\/README.html\">http:\/\/taizilongxu.gitbooks.io\/stackoverflow-about-python\/content\/3\/README.html<\/a><\/p>\n<h2>12 \u9e2d\u5b50\u7c7b\u578b<\/h2>\n<p>\u201c\u5f53\u770b\u5230\u4e00\u53ea\u9e1f\u8d70\u8d77\u6765\u50cf\u9e2d\u5b50\u3001\u6e38\u6cf3\u8d77\u6765\u50cf\u9e2d\u5b50\u3001\u53eb\u8d77\u6765\u4e5f\u50cf\u9e2d\u5b50\uff0c\u90a3\u4e48\u8fd9\u53ea\u9e1f\u5c31\u53ef\u4ee5\u88ab\u79f0\u4e3a\u9e2d\u5b50\u3002\u201d<\/p>\n<p>\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3\u5bf9\u8c61\u662f\u4ec0\u4e48\u7c7b\u578b\uff0c\u5230\u5e95\u662f\u4e0d\u662f\u9e2d\u5b50\uff0c\u53ea\u5173\u5fc3\u884c\u4e3a\u3002<\/p>\n<p>\u6bd4\u5982\u5728python\u4e2d\uff0c\u6709\u5f88\u591afile-like\u7684\u4e1c\u897f\uff0c\u6bd4\u5982StringIO,GzipFile,socket\u3002\u5b83\u4eec\u6709\u5f88\u591a\u76f8\u540c\u7684\u65b9\u6cd5\uff0c\u6211\u4eec\u628a\u5b83\u4eec\u5f53\u4f5c\u6587\u4ef6\u4f7f\u7528\u3002<\/p>\n<p>\u53c8\u6bd4\u5982list.extend()\u65b9\u6cd5\u4e2d,\u6211\u4eec\u5e76\u4e0d\u5173\u5fc3\u5b83\u7684\u53c2\u6570\u662f\u4e0d\u662flist,\u53ea\u8981\u5b83\u662f\u53ef\u8fed\u4ee3\u7684,\u6240\u4ee5\u5b83\u7684\u53c2\u6570\u53ef\u4ee5\u662flist\/tuple\/dict\/\u5b57\u7b26\u4e32\/\u751f\u6210\u5668\u7b49.<\/p>\n<p>\u9e2d\u5b50\u7c7b\u578b\u5728\u52a8\u6001\u8bed\u8a00\u4e2d\u7ecf\u5e38\u4f7f\u7528\uff0c\u975e\u5e38\u7075\u6d3b\uff0c\u4f7f\u5f97python\u4e0d\u60f3java\u90a3\u6837\u4e13\u95e8\u53bb\u5f04\u4e00\u5927\u5806\u7684\u8bbe\u8ba1\u6a21\u5f0f\u3002<\/p>\n<h2>13 Python\u4e2d\u91cd\u8f7d<\/h2>\n<p>\u5f15\u81ea\u77e5\u4e4e:<a href=\"http:\/\/www.zhihu.com\/question\/20053359\">http:\/\/www.zhihu.com\/question\/20053359<\/a><\/p>\n<p>\u51fd\u6570\u91cd\u8f7d\u4e3b\u8981\u662f\u4e3a\u4e86\u89e3\u51b3\u4e24\u4e2a\u95ee\u9898\u3002<\/p>\n<ol>\n<li>\u53ef\u53d8\u53c2\u6570\u7c7b\u578b\u3002<\/li>\n<li>\u53ef\u53d8\u53c2\u6570\u4e2a\u6570\u3002<\/li>\n<\/ol>\n<p>\u53e6\u5916\uff0c\u4e00\u4e2a\u57fa\u672c\u7684\u8bbe\u8ba1\u539f\u5219\u662f\uff0c\u4ec5\u4ec5\u5f53\u4e24\u4e2a\u51fd\u6570\u9664\u4e86\u53c2\u6570\u7c7b\u578b\u548c\u53c2\u6570\u4e2a\u6570\u4e0d\u540c\u4ee5\u5916\uff0c\u5176\u529f\u80fd\u662f\u5b8c\u5168\u76f8\u540c\u7684\uff0c\u6b64\u65f6\u624d\u4f7f\u7528\u51fd\u6570\u91cd\u8f7d\uff0c\u5982\u679c\u4e24\u4e2a\u51fd\u6570\u7684\u529f\u80fd\u5176\u5b9e\u4e0d\u540c\uff0c\u90a3\u4e48\u4e0d\u5e94\u5f53\u4f7f\u7528\u91cd\u8f7d\uff0c\u800c\u5e94\u5f53\u4f7f\u7528\u4e00\u4e2a\u540d\u5b57\u4e0d\u540c\u7684\u51fd\u6570\u3002<\/p>\n<p>\u597d\u5427\uff0c\u90a3\u4e48\u5bf9\u4e8e\u60c5\u51b5 1 \uff0c\u51fd\u6570\u529f\u80fd\u76f8\u540c\uff0c\u4f46\u662f\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\uff0cpython \u5982\u4f55\u5904\u7406\uff1f\u7b54\u6848\u662f\u6839\u672c\u4e0d\u9700\u8981\u5904\u7406\uff0c\u56e0\u4e3a python \u53ef\u4ee5\u63a5\u53d7\u4efb\u4f55\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u5982\u679c\u51fd\u6570\u7684\u529f\u80fd\u76f8\u540c\uff0c\u90a3\u4e48\u4e0d\u540c\u7684\u53c2\u6570\u7c7b\u578b\u5728 python \u4e2d\u5f88\u53ef\u80fd\u662f\u76f8\u540c\u7684\u4ee3\u7801\uff0c\u6ca1\u6709\u5fc5\u8981\u505a\u6210\u4e24\u4e2a\u4e0d\u540c\u51fd\u6570\u3002<\/p>\n<p>\u90a3\u4e48\u5bf9\u4e8e\u60c5\u51b5 2 \uff0c\u51fd\u6570\u529f\u80fd\u76f8\u540c\uff0c\u4f46\u53c2\u6570\u4e2a\u6570\u4e0d\u540c\uff0cpython \u5982\u4f55\u5904\u7406\uff1f\u5927\u5bb6\u77e5\u9053\uff0c\u7b54\u6848\u5c31\u662f\u7f3a\u7701\u53c2\u6570\u3002\u5bf9\u90a3\u4e9b\u7f3a\u5c11\u7684\u53c2\u6570\u8bbe\u5b9a\u4e3a\u7f3a\u7701\u53c2\u6570\u5373\u53ef\u89e3\u51b3\u95ee\u9898\u3002\u56e0\u4e3a\u4f60\u5047\u8bbe\u51fd\u6570\u529f\u80fd\u76f8\u540c\uff0c\u90a3\u4e48\u90a3\u4e9b\u7f3a\u5c11\u7684\u53c2\u6570\u7ec8\u5f52\u662f\u9700\u8981\u7528\u7684\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u9274\u4e8e\u60c5\u51b5 1 \u8ddf \u60c5\u51b5 2 \u90fd\u6709\u4e86\u89e3\u51b3\u65b9\u6848\uff0cpython \u81ea\u7136\u5c31\u4e0d\u9700\u8981\u51fd\u6570\u91cd\u8f7d\u4e86\u3002<\/p>\n<h2>14 \u65b0\u5f0f\u7c7b\u548c\u65e7\u5f0f\u7c7b<\/h2>\n<p>\u8fd9\u4e2a\u9762\u8bd5\u5b98\u95ee\u4e86,\u6211\u8bf4\u4e86\u8001\u534a\u5929,\u4e0d\u77e5\u9053\u4ed6\u95ee\u7684\u771f\u6b63\u610f\u56fe\u662f\u4ec0\u4e48.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/54867\/what-is-the-difference-between-old-style-and-new-style-classes-in-python\">stackoverflow<\/a><\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u5f88\u597d\u7684\u4ecb\u7ecd\u4e86\u65b0\u5f0f\u7c7b\u7684\u7279\u6027: <a href=\"http:\/\/www.cnblogs.com\/btchenguang\/archive\/2012\/09\/17\/2689146.html\">http:\/\/www.cnblogs.com\/btchenguang\/archive\/2012\/09\/17\/2689146.html<\/a><\/p>\n<p>\u65b0\u5f0f\u7c7b\u5f88\u65e9\u57282.2\u5c31\u51fa\u73b0\u4e86,\u6240\u4ee5\u65e7\u5f0f\u7c7b\u5b8c\u5168\u662f\u517c\u5bb9\u7684\u95ee\u9898,Python3\u91cc\u7684\u7c7b\u5168\u90e8\u90fd\u662f\u65b0\u5f0f\u7c7b.\u8fd9\u91cc\u6709\u4e00\u4e2aMRO\u95ee\u9898\u53ef\u4ee5\u4e86\u89e3\u4e0b(\u65b0\u5f0f\u7c7b\u662f\u5e7f\u5ea6\u4f18\u5148,\u65e7\u5f0f\u7c7b\u662f\u6df1\u5ea6\u4f18\u5148),&lt;Python\u6838\u5fc3\u7f16\u7a0b&gt;\u91cc\u8bb2\u7684\u4e5f\u5f88\u591a.<\/p>\n<h2>15 <code>__new__<\/code>\u548c<code>__init__<\/code>\u7684\u533a\u522b<\/h2>\n<p>\u8fd9\u4e2a<code>__new__<\/code>\u786e\u5b9e\u5f88\u5c11\u89c1\u5230,\u5148\u505a\u4e86\u89e3\u5427.<\/p>\n<ol>\n<li><code>__new__<\/code>\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5,\u800c<code>__init__<\/code>\u662f\u4e00\u4e2a\u5b9e\u4f8b\u65b9\u6cd5.<\/li>\n<li><code>__new__<\/code>\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u521b\u5efa\u7684\u5b9e\u4f8b,\u800c<code>__init__<\/code>\u4ec0\u4e48\u90fd\u4e0d\u8fd4\u56de.<\/li>\n<li>\u53ea\u6709\u5728<code>__new__<\/code>\u8fd4\u56de\u4e00\u4e2acls\u7684\u5b9e\u4f8b\u65f6\u540e\u9762\u7684<code>__init__<\/code>\u624d\u80fd\u88ab\u8c03\u7528.<\/li>\n<li>\u5f53\u521b\u5efa\u4e00\u4e2a\u65b0\u5b9e\u4f8b\u65f6\u8c03\u7528<code>__new__<\/code>,\u521d\u59cb\u5316\u4e00\u4e2a\u5b9e\u4f8b\u65f6\u7528<code>__init__<\/code>.<\/li>\n<\/ol>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/674304\/pythons-use-of-new-and-init\">stackoverflow<\/a><\/p>\n<p>ps: <code>__metaclass__<\/code>\u662f\u521b\u5efa\u7c7b\u65f6\u8d77\u4f5c\u7528.\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5206\u522b\u4f7f\u7528<code>__metaclass__<\/code>,<code>__new__<\/code>\u548c<code>__init__<\/code>\u6765\u5206\u522b\u5728\u7c7b\u521b\u5efa,\u5b9e\u4f8b\u521b\u5efa\u548c\u5b9e\u4f8b\u521d\u59cb\u5316\u7684\u65f6\u5019\u505a\u4e00\u4e9b\u5c0f\u624b\u811a.<\/p>\n<h2>16 \u5355\u4f8b\u6a21\u5f0f<\/h2>\n<p>\u8fd9\u4e2a\u7edd\u5bf9\u5e38\u8003\u554a.\u7edd\u5bf9\u8981\u8bb0\u4f4f1~2\u4e2a\u65b9\u6cd5,\u5f53\u65f6\u9762\u8bd5\u5b98\u662f\u8ba9\u624b\u5199\u7684.<\/p>\n<h3>1 \u4f7f\u7528<code>__new__<\/code>\u65b9\u6cd5<\/h3>\n<pre><code class=\"lang-python\">class Singleton(object):\n    def __new__(cls, *args, **kw):\n        if not hasattr(cls, '_instance'):\n            orig = super(Singleton, cls)\n            cls._instance = orig.__new__(cls, *args, **kw)\n        return cls._instance\n\nclass MyClass(Singleton):\n    a = 1<\/code><\/pre>\n<h3>2 \u5171\u4eab\u5c5e\u6027<\/h3>\n<p>\u521b\u5efa\u5b9e\u4f8b\u65f6\u628a\u6240\u6709\u5b9e\u4f8b\u7684<code>__dict__<\/code>\u6307\u5411\u540c\u4e00\u4e2a\u5b57\u5178,\u8fd9\u6837\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u5c5e\u6027\u548c\u65b9\u6cd5.<\/p>\n<pre><code class=\"lang-python\">\nclass Borg(object):\n    _state = {}\n    def __new__(cls, *args, **kw):\n        ob = super(Borg, cls).__new__(cls, *args, **kw)\n        ob.__dict__ = cls._state\n        return ob\n\nclass MyClass2(Borg):\n    a = 1<\/code><\/pre>\n<h3>3 \u88c5\u9970\u5668\u7248\u672c<\/h3>\n<pre><code class=\"lang-python\">def singleton(cls, *args, **kw):\n    instances = {}\n    def getinstance():\n        if cls not in instances:\n            instances[cls] = cls(*args, **kw)\n        return instances[cls]\n    return getinstance\n\n@singleton\nclass MyClass:\n  ...<\/code><\/pre>\n<h3>4 import\u65b9\u6cd5<\/h3>\n<p>\u4f5c\u4e3apython\u7684\u6a21\u5757\u662f\u5929\u7136\u7684\u5355\u4f8b\u6a21\u5f0f<\/p>\n<pre><code class=\"lang-python\"># mysingleton.py\nclass My_Singleton(object):\n    def foo(self):\n        pass\n\nmy_singleton = My_Singleton()\n\n# to use\nfrom mysingleton import my_singleton\n\nmy_singleton.foo()\n<\/code><\/pre>\n<h2>17 Python\u4e2d\u7684\u4f5c\u7528\u57df<\/h2>\n<p>Python \u4e2d\uff0c\u4e00\u4e2a\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u603b\u662f\u7531\u5728\u4ee3\u7801\u4e2d\u88ab\u8d4b\u503c\u7684\u5730\u65b9\u6240\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u5f53 Python \u9047\u5230\u4e00\u4e2a\u53d8\u91cf\u7684\u8bdd\u4ed6\u4f1a\u6309\u7167\u8fd9\u6837\u7684\u987a\u5e8f\u8fdb\u884c\u641c\u7d22\uff1a<\/p>\n<p>\u672c\u5730\u4f5c\u7528\u57df\uff08Local\uff09\u2192\u5f53\u524d\u4f5c\u7528\u57df\u88ab\u5d4c\u5165\u7684\u672c\u5730\u4f5c\u7528\u57df\uff08Enclosing locals\uff09\u2192\u5168\u5c40\/\u6a21\u5757\u4f5c\u7528\u57df\uff08Global\uff09\u2192\u5185\u7f6e\u4f5c\u7528\u57df\uff08Built-in\uff09<\/p>\n<h2>18 GIL\u7ebf\u7a0b\u5168\u5c40\u9501<\/h2>\n<p>\u7ebf\u7a0b\u5168\u5c40\u9501(Global Interpreter Lock),\u5373Python\u4e3a\u4e86\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168\u800c\u91c7\u53d6\u7684\u72ec\u7acb\u7ebf\u7a0b\u8fd0\u884c\u7684\u9650\u5236,\u8bf4\u767d\u4e86\u5c31\u662f\u4e00\u4e2a\u6838\u53ea\u80fd\u5728\u540c\u4e00\u65f6\u95f4\u8fd0\u884c\u4e00\u4e2a\u7ebf\u7a0b.<\/p>\n<p>\u89c1<a href=\"http:\/\/www.oschina.net\/translate\/pythons-hardest-problem\">Python \u6700\u96be\u7684\u95ee\u9898<\/a><\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\u5c31\u662f\u591a\u8fdb\u7a0b\u548c\u4e0b\u9762\u7684\u534f\u7a0b(\u534f\u7a0b\u4e5f\u53ea\u662f\u5355CPU,\u4f46\u662f\u80fd\u51cf\u5c0f\u5207\u6362\u4ee3\u4ef7\u63d0\u5347\u6027\u80fd).<\/p>\n<h2>19 \u534f\u7a0b<\/h2>\n<p>\u77e5\u4e4e\u88ab\u95ee\u5230\u4e86,\u5475\u5475\u54d2,\u8dea\u4e86<\/p>\n<p>\u7b80\u5355\u70b9\u8bf4\u534f\u7a0b\u662f\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u7684\u5347\u7ea7\u7248,\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u90fd\u9762\u4e34\u7740\u5185\u6838\u6001\u548c\u7528\u6237\u6001\u7684\u5207\u6362\u95ee\u9898\u800c\u8017\u8d39\u8bb8\u591a\u5207\u6362\u65f6\u95f4,\u800c\u534f\u7a0b\u5c31\u662f\u7528\u6237\u81ea\u5df1\u63a7\u5236\u5207\u6362\u7684\u65f6\u673a,\u4e0d\u518d\u9700\u8981\u9677\u5165\u7cfb\u7edf\u7684\u5185\u6838\u6001.<\/p>\n<p>Python\u91cc\u6700\u5e38\u89c1\u7684yield\u5c31\u662f\u534f\u7a0b\u7684\u601d\u60f3!\u53ef\u4ee5\u67e5\u770b\u7b2c\u4e5d\u4e2a\u95ee\u9898.<\/p>\n<h2>20 \u95ed\u5305<\/h2>\n<p>\u95ed\u5305(closure)\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u91cd\u8981\u7684\u8bed\u6cd5\u7ed3\u6784\u3002\u95ed\u5305\u4e5f\u662f\u4e00\u79cd\u7ec4\u7ec7\u4ee3\u7801\u7684\u7ed3\u6784\uff0c\u5b83\u540c\u6837\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u91cd\u590d\u4f7f\u7528\u6027\u3002<\/p>\n<p>\u5f53\u4e00\u4e2a\u5185\u5d4c\u51fd\u6570\u5f15\u7528\u5176\u5916\u90e8\u4f5c\u4f5c\u7528\u57df\u7684\u53d8\u91cf,\u6211\u4eec\u5c31\u4f1a\u5f97\u5230\u4e00\u4e2a\u95ed\u5305. \u603b\u7ed3\u4e00\u4e0b,\u521b\u5efa\u4e00\u4e2a\u95ed\u5305\u5fc5\u987b\u6ee1\u8db3\u4ee5\u4e0b\u51e0\u70b9:<\/p>\n<ol>\n<li>\u5fc5\u987b\u6709\u4e00\u4e2a\u5185\u5d4c\u51fd\u6570<\/li>\n<li>\u5185\u5d4c\u51fd\u6570\u5fc5\u987b\u5f15\u7528\u5916\u90e8\u51fd\u6570\u4e2d\u7684\u53d8\u91cf<\/li>\n<li>\u5916\u90e8\u51fd\u6570\u7684\u8fd4\u56de\u503c\u5fc5\u987b\u662f\u5185\u5d4c\u51fd\u6570<\/li>\n<\/ol>\n<p>\u611f\u89c9\u95ed\u5305\u8fd8\u662f\u6709\u96be\u5ea6\u7684,\u51e0\u53e5\u8bdd\u662f\u8bf4\u4e0d\u660e\u767d\u7684,\u8fd8\u662f\u67e5\u67e5\u76f8\u5173\u8d44\u6599.<\/p>\n<p>\u91cd\u70b9\u662f\u51fd\u6570\u8fd0\u884c\u540e\u5e76\u4e0d\u4f1a\u88ab\u64a4\u9500,\u5c31\u50cf16\u9898\u7684instance\u5b57\u5178\u4e00\u6837,\u5f53\u51fd\u6570\u8fd0\u884c\u5b8c\u540e,instance\u5e76\u4e0d\u88ab\u9500\u6bc1,\u800c\u662f\u7ee7\u7eed\u7559\u5728\u5185\u5b58\u7a7a\u95f4\u91cc.\u8fd9\u4e2a\u529f\u80fd\u7c7b\u4f3c\u7c7b\u91cc\u7684\u7c7b\u53d8\u91cf,\u53ea\u4e0d\u8fc7\u8fc1\u79fb\u5230\u4e86\u51fd\u6570\u4e0a.<\/p>\n<p>\u95ed\u5305\u5c31\u50cf\u4e2a\u7a7a\u5fc3\u7403\u4e00\u6837,\u4f60\u77e5\u9053\u5916\u9762\u548c\u91cc\u9762,\u4f46\u4f60\u4e0d\u77e5\u9053\u4e2d\u95f4\u662f\u4ec0\u4e48\u6837.<\/p>\n<h2>21 lambda\u51fd\u6570<\/h2>\n<p>\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u533f\u540d\u51fd\u6570,\u4e3a\u4ec0\u4e48\u53eblambda?\u56e0\u4e3a\u548c\u540e\u9762\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\u6709\u5173.<\/p>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.zhihu.com\/question\/20125256\">\u77e5\u4e4e<\/a><\/p>\n<h2>22 Python\u51fd\u6570\u5f0f\u7f16\u7a0b<\/h2>\n<p>\u8fd9\u4e2a\u9700\u8981\u9002\u5f53\u7684\u4e86\u89e3\u4e00\u4e0b\u5427,\u6bd5\u7adf\u51fd\u6570\u5f0f\u7f16\u7a0b\u5728Python\u4e2d\u4e5f\u505a\u4e86\u5f15\u7528.<\/p>\n<p>\u63a8\u8350: <a href=\"http:\/\/coolshell.cn\/articles\/10822.html\">\u9177\u58f3<\/a><\/p>\n<p>python\u4e2d\u51fd\u6570\u5f0f\u7f16\u7a0b\u652f\u6301:<\/p>\n<p>filter \u51fd\u6570\u7684\u529f\u80fd\u76f8\u5f53\u4e8e\u8fc7\u6ee4\u5668\u3002\u8c03\u7528\u4e00\u4e2a\u5e03\u5c14\u51fd\u6570<code>bool_func<\/code>\u6765\u8fed\u4ee3\u904d\u5386\u6bcf\u4e2aseq\u4e2d\u7684\u5143\u7d20\uff1b\u8fd4\u56de\u4e00\u4e2a\u4f7f<code>bool_seq<\/code>\u8fd4\u56de\u503c\u4e3atrue\u7684\u5143\u7d20\u7684\u5e8f\u5217\u3002<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt;a = [1,2,3,4,5,6,7]\n&gt;&gt;&gt;b = filter(lambda x: x &gt; 5, a)\n&gt;&gt;&gt;print b\n&gt;&gt;&gt;[6,7]<\/code><\/pre>\n<p>map\u51fd\u6570\u662f\u5bf9\u4e00\u4e2a\u5e8f\u5217\u7684\u6bcf\u4e2a\u9879\u4f9d\u6b21\u6267\u884c\u51fd\u6570\uff0c\u4e0b\u9762\u662f\u5bf9\u4e00\u4e2a\u5e8f\u5217\u6bcf\u4e2a\u9879\u90fd\u4e58\u4ee52\uff1a<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; a = map(lambda x:x*2,[1,2,3])\n&gt;&gt;&gt; list(a)\n[2, 4, 6]<\/code><\/pre>\n<p>reduce\u51fd\u6570\u662f\u5bf9\u4e00\u4e2a\u5e8f\u5217\u7684\u6bcf\u4e2a\u9879\u8fed\u4ee3\u8c03\u7528\u51fd\u6570\uff0c\u4e0b\u9762\u662f\u6c423\u7684\u9636\u4e58\uff1a<\/p>\n<pre><code class=\"lang-python\">&gt;&gt;&gt; reduce(lambda x,y:x*y,range(1,4))\n6<\/code><\/pre>\n<h2>23 Python\u91cc\u7684\u62f7\u8d1d<\/h2>\n<p>\u5f15\u7528\u548ccopy(),deepcopy()\u7684\u533a\u522b<\/p>\n<pre><code class=\"lang-python\">import copy\na = [1, 2, 3, 4, ['a', 'b']]  #\u539f\u59cb\u5bf9\u8c61\n\nb = a  #\u8d4b\u503c\uff0c\u4f20\u5bf9\u8c61\u7684\u5f15\u7528\nc = copy.copy(a)  #\u5bf9\u8c61\u62f7\u8d1d\uff0c\u6d45\u62f7\u8d1d\nd = copy.deepcopy(a)  #\u5bf9\u8c61\u62f7\u8d1d\uff0c\u6df1\u62f7\u8d1d\n\na.append(5)  #\u4fee\u6539\u5bf9\u8c61a\na[4].append('c')  #\u4fee\u6539\u5bf9\u8c61a\u4e2d\u7684['a', 'b']\u6570\u7ec4\u5bf9\u8c61\n\nprint 'a = ', a\nprint 'b = ', b\nprint 'c = ', c\nprint 'd = ', d\n\n\u8f93\u51fa\u7ed3\u679c\uff1a\na =  [1, 2, 3, 4, ['a', 'b', 'c'], 5]\nb =  [1, 2, 3, 4, ['a', 'b', 'c'], 5]\nc =  [1, 2, 3, 4, ['a', 'b', 'c']]\nd =  [1, 2, 3, 4, ['a', 'b']]<\/code><\/pre>\n<h2>24 Python\u5783\u573e\u56de\u6536\u673a\u5236<\/h2>\n<p>Python GC\u4e3b\u8981\u4f7f\u7528\u5f15\u7528\u8ba1\u6570\uff08reference counting\uff09\u6765\u8ddf\u8e2a\u548c\u56de\u6536\u5783\u573e\u3002\u5728\u5f15\u7528\u8ba1\u6570\u7684\u57fa\u7840\u4e0a\uff0c\u901a\u8fc7\u201c\u6807\u8bb0-\u6e05\u9664\u201d\uff08mark and sweep\uff09\u89e3\u51b3\u5bb9\u5668\u5bf9\u8c61\u53ef\u80fd\u4ea7\u751f\u7684\u5faa\u73af\u5f15\u7528\u95ee\u9898\uff0c\u901a\u8fc7\u201c\u5206\u4ee3\u56de\u6536\u201d\uff08generation collection\uff09\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\u7684\u65b9\u6cd5\u63d0\u9ad8\u5783\u573e\u56de\u6536\u6548\u7387\u3002<\/p>\n<h3>1 \u5f15\u7528\u8ba1\u6570<\/h3>\n<p>PyObject\u662f\u6bcf\u4e2a\u5bf9\u8c61\u5fc5\u6709\u7684\u5185\u5bb9\uff0c\u5176\u4e2d<code>ob_refcnt<\/code>\u5c31\u662f\u505a\u4e3a\u5f15\u7528\u8ba1\u6570\u3002\u5f53\u4e00\u4e2a\u5bf9\u8c61\u6709\u65b0\u7684\u5f15\u7528\u65f6\uff0c\u5b83\u7684<code>ob_refcnt<\/code>\u5c31\u4f1a\u589e\u52a0\uff0c\u5f53\u5f15\u7528\u5b83\u7684\u5bf9\u8c61\u88ab\u5220\u9664\uff0c\u5b83\u7684<code>ob_refcnt<\/code>\u5c31\u4f1a\u51cf\u5c11.\u5f15\u7528\u8ba1\u6570\u4e3a0\u65f6\uff0c\u8be5\u5bf9\u8c61\u751f\u547d\u5c31\u7ed3\u675f\u4e86\u3002<\/p>\n<p>\u4f18\u70b9:<\/p>\n<ol>\n<li>\u7b80\u5355<\/li>\n<li>\u5b9e\u65f6\u6027<\/li>\n<\/ol>\n<p>\u7f3a\u70b9:<\/p>\n<ol>\n<li>\u7ef4\u62a4\u5f15\u7528\u8ba1\u6570\u6d88\u8017\u8d44\u6e90<\/li>\n<li>\u5faa\u73af\u5f15\u7528<\/li>\n<\/ol>\n<h3>2 \u6807\u8bb0-\u6e05\u9664\u673a\u5236<\/h3>\n<p>\u57fa\u672c\u601d\u8def\u662f\u5148\u6309\u9700\u5206\u914d\uff0c\u7b49\u5230\u6ca1\u6709\u7a7a\u95f2\u5185\u5b58\u7684\u65f6\u5019\u4ece\u5bc4\u5b58\u5668\u548c\u7a0b\u5e8f\u6808\u4e0a\u7684\u5f15\u7528\u51fa\u53d1\uff0c\u904d\u5386\u4ee5\u5bf9\u8c61\u4e3a\u8282\u70b9\u3001\u4ee5\u5f15\u7528\u4e3a\u8fb9\u6784\u6210\u7684\u56fe\uff0c\u628a\u6240\u6709\u53ef\u4ee5\u8bbf\u95ee\u5230\u7684\u5bf9\u8c61\u6253\u4e0a\u6807\u8bb0\uff0c\u7136\u540e\u6e05\u626b\u4e00\u904d\u5185\u5b58\u7a7a\u95f4\uff0c\u628a\u6240\u6709\u6ca1\u6807\u8bb0\u7684\u5bf9\u8c61\u91ca\u653e\u3002<\/p>\n<h3>3 \u5206\u4ee3\u6280\u672f<\/h3>\n<p>\u5206\u4ee3\u56de\u6536\u7684\u6574\u4f53\u601d\u60f3\u662f\uff1a\u5c06\u7cfb\u7edf\u4e2d\u7684\u6240\u6709\u5185\u5b58\u5757\u6839\u636e\u5176\u5b58\u6d3b\u65f6\u95f4\u5212\u5206\u4e3a\u4e0d\u540c\u7684\u96c6\u5408\uff0c\u6bcf\u4e2a\u96c6\u5408\u5c31\u6210\u4e3a\u4e00\u4e2a\u201c\u4ee3\u201d\uff0c\u5783\u573e\u6536\u96c6\u9891\u7387\u968f\u7740\u201c\u4ee3\u201d\u7684\u5b58\u6d3b\u65f6\u95f4\u7684\u589e\u5927\u800c\u51cf\u5c0f\uff0c\u5b58\u6d3b\u65f6\u95f4\u901a\u5e38\u5229\u7528\u7ecf\u8fc7\u51e0\u6b21\u5783\u573e\u56de\u6536\u6765\u5ea6\u91cf\u3002<\/p>\n<p>Python\u9ed8\u8ba4\u5b9a\u4e49\u4e86\u4e09\u4ee3\u5bf9\u8c61\u96c6\u5408\uff0c\u7d22\u5f15\u6570\u8d8a\u5927\uff0c\u5bf9\u8c61\u5b58\u6d3b\u65f6\u95f4\u8d8a\u957f\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a<br \/>\u5f53\u67d0\u4e9b\u5185\u5b58\u5757M\u7ecf\u8fc7\u4e863\u6b21\u5783\u573e\u6536\u96c6\u7684\u6e05\u6d17\u4e4b\u540e\u8fd8\u5b58\u6d3b\u65f6\uff0c\u6211\u4eec\u5c31\u5c06\u5185\u5b58\u5757M\u5212\u5230\u4e00\u4e2a\u96c6\u5408A\u4e2d\u53bb\uff0c\u800c\u65b0\u5206\u914d\u7684\u5185\u5b58\u90fd\u5212\u5206\u5230\u96c6\u5408B\u4e2d\u53bb\u3002\u5f53\u5783\u573e\u6536\u96c6\u5f00\u59cb\u5de5\u4f5c\u65f6\uff0c\u5927\u591a\u6570\u60c5\u51b5\u90fd\u53ea\u5bf9\u96c6\u5408B\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u800c\u5bf9\u96c6\u5408A\u8fdb\u884c\u5783\u573e\u56de\u6536\u8981\u9694\u76f8\u5f53\u957f\u4e00\u6bb5\u65f6\u95f4\u540e\u624d\u8fdb\u884c\uff0c\u8fd9\u5c31\u4f7f\u5f97\u5783\u573e\u6536\u96c6\u673a\u5236\u9700\u8981\u5904\u7406\u7684\u5185\u5b58\u5c11\u4e86\uff0c\u6548\u7387\u81ea\u7136\u5c31\u63d0\u9ad8\u4e86\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u96c6\u5408B\u4e2d\u7684\u67d0\u4e9b\u5185\u5b58\u5757\u7531\u4e8e\u5b58\u6d3b\u65f6\u95f4\u957f\u800c\u4f1a\u88ab\u8f6c\u79fb\u5230\u96c6\u5408A\u4e2d\uff0c\u5f53\u7136\uff0c\u96c6\u5408A\u4e2d\u5b9e\u9645\u4e0a\u4e5f\u5b58\u5728\u4e00\u4e9b\u5783\u573e\uff0c\u8fd9\u4e9b\u5783\u573e\u7684\u56de\u6536\u4f1a\u56e0\u4e3a\u8fd9\u79cd\u5206\u4ee3\u7684\u673a\u5236\u800c\u88ab\u5ef6\u8fdf\u3002<\/p>\n<h2>25 Python\u7684List<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.jianshu.com\/p\/J4U6rR\">http:\/\/www.jianshu.com\/p\/J4U6rR<\/a><\/p>\n<h2>26 Python\u7684is<\/h2>\n<p>is\u662f\u5bf9\u6bd4\u5730\u5740,==\u662f\u5bf9\u6bd4\u503c<\/p>\n<h2>27 read,readline\u548creadlines<\/h2>\n<ul>\n<li>read        \u8bfb\u53d6\u6574\u4e2a\u6587\u4ef6<\/li>\n<li>readline    \u8bfb\u53d6\u4e0b\u4e00\u884c,\u4f7f\u7528\u751f\u6210\u5668\u65b9\u6cd5<\/li>\n<li>readlines   \u8bfb\u53d6\u6574\u4e2a\u6587\u4ef6\u5230\u4e00\u4e2a\u8fed\u4ee3\u5668\u4ee5\u4f9b\u6211\u4eec\u904d\u5386<\/li>\n<\/ul>\n<h2>28 Python2\u548c3\u7684\u533a\u522b<\/h2>\n<h1>\u64cd\u4f5c\u7cfb\u7edf<\/h1>\n<h2>1 select,poll\u548cepoll<\/h2>\n<p>\u5176\u5b9e\u6240\u6709\u7684I\/O\u90fd\u662f\u8f6e\u8be2\u7684\u65b9\u6cd5,\u53ea\u4e0d\u8fc7\u5b9e\u73b0\u7684\u5c42\u9762\u4e0d\u540c\u7f62\u4e86.<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u53ef\u80fd\u6709\u70b9\u6df1\u5165\u4e86,\u4f46\u76f8\u4fe1\u80fd\u56de\u7b54\u51fa\u8fd9\u4e2a\u95ee\u9898\u662f\u5bf9I\/O\u591a\u8def\u590d\u7528\u6709\u5f88\u597d\u7684\u4e86\u89e3\u4e86.\u5176\u4e2dtornado\u4f7f\u7528\u7684\u5c31\u662fepoll\u7684.<\/p>\n<p><a href=\"http:\/\/www.cnblogs.com\/Anker\/p\/3265058.html\">selec,poll\u548cepoll\u533a\u522b\u603b\u7ed3<\/a><\/p>\n<p>\u57fa\u672c\u4e0aselect\u67093\u4e2a\u7f3a\u70b9:<\/p>\n<ol>\n<li>\u8fde\u63a5\u6570\u53d7\u9650<\/li>\n<li>\u67e5\u627e\u914d\u5bf9\u901f\u5ea6\u6162<\/li>\n<li>\u6570\u636e\u7531\u5185\u6838\u62f7\u8d1d\u5230\u7528\u6237\u6001<\/li>\n<\/ol>\n<p>poll\u6539\u5584\u4e86\u7b2c\u4e00\u4e2a\u7f3a\u70b9<\/p>\n<p>epoll\u6539\u4e86\u4e09\u4e2a\u7f3a\u70b9.<\/p>\n<p>\u5173\u4e8eepoll\u7684: <a href=\"http:\/\/www.cnblogs.com\/my_life\/articles\/3968782.html\">http:\/\/www.cnblogs.com\/my_life\/articles\/3968782.html<\/a><\/p>\n<h2>2 \u8c03\u5ea6\u7b97\u6cd5<\/h2>\n<ol>\n<li>\u5148\u6765\u5148\u670d\u52a1<\/li>\n<li>\u77ed\u4f5c\u4e1a\u4f18\u5148<\/li>\n<li>\u6700\u9ad8\u4f18\u5148\u6743\u8c03\u5ea6<\/li>\n<li>\u65f6\u95f4\u7247\u8f6e\u8f6c<\/li>\n<li>\u591a\u7ea7\u53cd\u9988\u961f\u5217\u8c03\u5ea6<\/li>\n<\/ol>\n<p>\u5b9e\u65f6\u8c03\u5ea6\u7b97\u6cd5:<\/p>\n<ol>\n<li>\u6700\u65e9\u622a\u81f3\u65f6\u95f4\u4f18\u5148 EDF<\/li>\n<li>\u6700\u4f4e\u677e\u5f1b\u5ea6\u4f18\u5148 LLF<\/li>\n<\/ol>\n<h2>3 \u6b7b\u9501<\/h2>\n<p>\u539f\u56e0:<\/p>\n<ol>\n<li>\u7ade\u4e89\u8d44\u6e90<\/li>\n<li>\u7a0b\u5e8f\u63a8\u8fdb\u987a\u5e8f\u4e0d\u5f53<\/li>\n<\/ol>\n<p>\u5fc5\u8981\u6761\u4ef6:<\/p>\n<ol>\n<li>\u4e92\u65a5\u6761\u4ef6<\/li>\n<li>\u8bf7\u6c42\u548c\u4fdd\u6301\u6761\u4ef6<\/li>\n<li>\u4e0d\u5265\u593a\u6761\u4ef6<\/li>\n<li>\u73af\u8def\u7b49\u5f85\u6761\u4ef6<\/li>\n<\/ol>\n<p>\u5904\u7406\u6b7b\u9501\u57fa\u672c\u65b9\u6cd5:<\/p>\n<ol>\n<li>\u9884\u9632\u6b7b\u9501(\u6452\u5f03\u96641\u4ee5\u5916\u7684\u6761\u4ef6)<\/li>\n<li>\u907f\u514d\u6b7b\u9501(\u94f6\u884c\u5bb6\u7b97\u6cd5)<\/li>\n<li>\u68c0\u6d4b\u6b7b\u9501(\u8d44\u6e90\u5206\u914d\u56fe)<\/li>\n<li>\n<p>\u89e3\u9664\u6b7b\u9501<\/p>\n<ol>\n<li>\u5265\u593a\u8d44\u6e90<\/li>\n<li>\u64a4\u9500\u8fdb\u7a0b<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>4 \u7a0b\u5e8f\u7f16\u8bd1\u4e0e\u94fe\u63a5<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.ruanyifeng.com\/blog\/2014\/11\/compiler.html\">http:\/\/www.ruanyifeng.com\/blog\/2014\/11\/compiler.html<\/a><\/p>\n<p>Bulid\u8fc7\u7a0b\u53ef\u4ee5\u5206\u89e3\u4e3a4\u4e2a\u6b65\u9aa4:\u9884\u5904\u7406(Prepressing), \u7f16\u8bd1(Compilation)\u3001\u6c47\u7f16(Assembly)\u3001\u94fe\u63a5(Linking)<\/p>\n<p>\u4ee5c\u8bed\u8a00\u4e3a\u4f8b:<\/p>\n<h3>1 \u9884\u5904\u7406<\/h3>\n<p>\u9884\u7f16\u8bd1\u8fc7\u7a0b\u4e3b\u8981\u5904\u7406\u90a3\u4e9b\u6e90\u6587\u4ef6\u4e2d\u7684\u4ee5\u201c#\u201d\u5f00\u59cb\u7684\u9884\u7f16\u8bd1\u6307\u4ee4\uff0c\u4e3b\u8981\u5904\u7406\u89c4\u5219\u6709\uff1a<\/p>\n<ol>\n<li>\u5c06\u6240\u6709\u7684\u201c#define\u201d\u5220\u9664\uff0c\u5e76\u5c55\u5f00\u6240\u7528\u7684\u5b8f\u5b9a\u4e49<\/li>\n<li>\u5904\u7406\u6240\u6709\u6761\u4ef6\u9884\u7f16\u8bd1\u6307\u4ee4\uff0c\u6bd4\u5982\u201c#if\u201d\u3001\u201c#ifdef\u201d\u3001 \u201c#elif\u201d\u3001\u201c#endif\u201d<\/li>\n<li>\u5904\u7406\u201c#include\u201d\u9884\u7f16\u8bd1\u6307\u4ee4\uff0c\u5c06\u88ab\u5305\u542b\u7684\u6587\u4ef6\u63d2\u5165\u5230\u8be5\u7f16\u8bd1\u6307\u4ee4\u7684\u4f4d\u7f6e\uff0c\u6ce8\uff1a\u6b64\u8fc7\u7a0b\u662f\u9012\u5f52\u8fdb\u884c\u7684<\/li>\n<li>\u5220\u9664\u6240\u6709\u6ce8\u91ca<\/li>\n<li>\u6dfb\u52a0\u884c\u53f7\u548c\u6587\u4ef6\u540d\u6807\u8bc6\uff0c\u4ee5\u4fbf\u4e8e\u7f16\u8bd1\u65f6\u7f16\u8bd1\u5668\u4ea7\u751f\u8c03\u8bd5\u7528\u7684\u884c\u53f7\u4fe1\u606f\u4ee5\u53ca\u7528\u4e8e\u7f16\u8bd1\u65f6\u4ea7\u751f\u7f16\u8bd1\u9519\u8bef\u6216\u8b66\u544a\u65f6\u53ef\u663e\u793a\u884c\u53f7<\/li>\n<li>\u4fdd\u7559\u6240\u6709\u7684#pragma\u7f16\u8bd1\u5668\u6307\u4ee4\u3002<\/li>\n<\/ol>\n<h3>2 \u7f16\u8bd1<\/h3>\n<p>\u7f16\u8bd1\u8fc7\u7a0b\u5c31\u662f\u628a\u9884\u5904\u7406\u5b8c\u7684\u6587\u4ef6\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\u53ca\u4f18\u5316\u540e\u751f\u6210\u76f8\u5e94\u7684\u6c47\u7f16\u4ee3\u7801\u6587\u4ef6\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u6574\u4e2a\u7a0b\u5e8f\u6784\u5efa\u7684\u6838\u5fc3\u90e8\u5206\u3002<\/p>\n<h3>3 \u6c47\u7f16<\/h3>\n<p>\u6c47\u7f16\u5668\u662f\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u5316\u6210\u673a\u5668\u53ef\u4ee5\u6267\u884c\u7684\u6307\u4ee4\uff0c\u6bcf\u4e00\u6761\u6c47\u7f16\u8bed\u53e5\u51e0\u4e4e\u90fd\u662f\u4e00\u6761\u673a\u5668\u6307\u4ee4\u3002\u7ecf\u8fc7\u7f16\u8bd1\u3001\u94fe\u63a5\u3001\u6c47\u7f16\u8f93\u51fa\u7684\u6587\u4ef6\u6210\u4e3a\u76ee\u6807\u6587\u4ef6(Object File)<\/p>\n<h3>4 \u94fe\u63a5<\/h3>\n<p>\u94fe\u63a5\u7684\u4e3b\u8981\u5185\u5bb9\u5c31\u662f\u628a\u5404\u4e2a\u6a21\u5757\u76f4\u63a5\u7231\u4f60\u76f8\u4e92\u5f15\u7528\u7684\u90e8\u5206\u5904\u7406\u597d\uff0c\u4f7f\u5404\u4e2a\u6a21\u5757\u53ef\u4ee5\u6b63\u786e\u7684\u62fc\u63a5\u3002<br \/>\u94fe\u63a5\u7684\u4e3b\u8981\u8fc7\u7a0b\u5305\u5757 \u5730\u5740\u548c\u7a7a\u95f4\u7684\u5206\u914d\uff08Address and Storage Allocation\uff09\u3001\u7b26\u53f7\u51b3\u8bae(Symbol Resolution)\u548c\u91cd\u5b9a\u4f4d(Relocation)\u7b49\u6b65\u9aa4\u3002<\/p>\n<h2>5 \u9759\u6001\u94fe\u63a5\u548c\u52a8\u6001\u94fe\u63a5<\/h2>\n<p>\u9759\u6001\u94fe\u63a5\u65b9\u6cd5\uff1a\u9759\u6001\u94fe\u63a5\u7684\u65f6\u5019\uff0c\u8f7d\u5165\u4ee3\u7801\u5c31\u4f1a\u628a\u7a0b\u5e8f\u4f1a\u7528\u5230\u7684\u52a8\u6001\u4ee3\u7801\u6216\u52a8\u6001\u4ee3\u7801\u7684\u5730\u5740\u786e\u5b9a\u4e0b\u6765<br \/>\u9759\u6001\u5e93\u7684\u94fe\u63a5\u53ef\u4ee5\u4f7f\u7528\u9759\u6001\u94fe\u63a5\uff0c\u52a8\u6001\u94fe\u63a5\u5e93\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u79cd\u65b9\u6cd5\u94fe\u63a5\u5bfc\u5165\u5e93<\/p>\n<p>\u52a8\u6001\u94fe\u63a5\u65b9\u6cd5\uff1a\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u7684\u7a0b\u5e8f\u5e76\u4e0d\u5728\u4e00\u5f00\u59cb\u5c31\u5b8c\u6210\u52a8\u6001\u94fe\u63a5\uff0c\u800c\u662f\u76f4\u5230\u771f\u6b63\u8c03\u7528\u52a8\u6001\u5e93\u4ee3\u7801\u65f6\uff0c\u8f7d\u5165\u7a0b\u5e8f\u624d\u8ba1\u7b97(\u88ab\u8c03\u7528\u7684\u90a3\u90e8\u5206)\u52a8\u6001\u4ee3\u7801\u7684\u903b\u8f91\u5730\u5740\uff0c\u7136\u540e\u7b49\u5230\u67d0\u4e2a\u65f6\u5019\uff0c\u7a0b\u5e8f\u53c8\u9700\u8981\u8c03\u7528\u53e6\u5916\u67d0\u5757\u52a8\u6001\u4ee3\u7801\u65f6\uff0c\u8f7d\u5165\u7a0b\u5e8f\u53c8\u53bb\u8ba1\u7b97\u8fd9\u90e8\u5206\u4ee3\u7801\u7684\u903b\u8f91\u5730\u5740\uff0c\u6240\u4ee5\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u7a0b\u5e8f\u521d\u59cb\u5316\u65f6\u95f4\u8f83\u77ed\uff0c\u4f46\u8fd0\u884c\u671f\u95f4\u7684\u6027\u80fd\u6bd4\u4e0d\u4e0a\u9759\u6001\u94fe\u63a5\u7684\u7a0b\u5e8f<\/p>\n<h2>6 \u865a\u62df\u5185\u5b58\u6280\u672f<\/h2>\n<p>\u865a\u62df\u5b58\u50a8\u5668\u662f\u503c\u5177\u6709\u8bf7\u6c42\u8c03\u5165\u529f\u80fd\u548c\u7f6e\u6362\u529f\u80fd,\u80fd\u4ece\u903b\u8f91\u4e0a\u5bf9\u5185\u5b58\u5bb9\u91cf\u52a0\u4ee5\u6269\u5145\u7684\u4e00\u79cd\u5b58\u50a8\u7cfb\u7edf.<\/p>\n<h2>7 \u5206\u9875\u548c\u5206\u6bb5<\/h2>\n<p>\u5206\u9875: \u7528\u6237\u7a0b\u5e8f\u7684\u5730\u5740\u7a7a\u95f4\u88ab\u5212\u5206\u6210\u82e5\u5e72\u56fa\u5b9a\u5927\u5c0f\u7684\u533a\u57df\uff0c\u79f0\u4e3a\u201c\u9875\u201d\uff0c\u76f8\u5e94\u5730\uff0c\u5185\u5b58\u7a7a\u95f4\u5206\u6210\u82e5\u5e72\u4e2a\u7269\u7406\u5757\uff0c\u9875\u548c\u5757\u7684\u5927\u5c0f\u76f8\u7b49\u3002\u53ef\u5c06\u7528\u6237\u7a0b\u5e8f\u7684\u4efb\u4e00\u9875\u653e\u5728\u5185\u5b58\u7684\u4efb\u4e00\u5757\u4e2d\uff0c\u5b9e\u73b0\u4e86\u79bb\u6563\u5206\u914d\u3002<\/p>\n<p>\u5206\u6bb5: \u5c06\u7528\u6237\u7a0b\u5e8f\u5730\u5740\u7a7a\u95f4\u5206\u6210\u82e5\u5e72\u4e2a\u5927\u5c0f\u4e0d\u7b49\u7684\u6bb5\uff0c\u6bcf\u6bb5\u53ef\u4ee5\u5b9a\u4e49\u4e00\u7ec4\u76f8\u5bf9\u5b8c\u6574\u7684\u903b\u8f91\u4fe1\u606f\u3002\u5b58\u50a8\u5206\u914d\u65f6\uff0c\u4ee5\u6bb5\u4e3a\u5355\u4f4d\uff0c\u6bb5\u4e0e\u6bb5\u5728\u5185\u5b58\u4e2d\u53ef\u4ee5\u4e0d\u76f8\u90bb\u63a5\uff0c\u4e5f\u5b9e\u73b0\u4e86\u79bb\u6563\u5206\u914d\u3002<\/p>\n<h3>\u5206\u9875\u4e0e\u5206\u6bb5\u7684\u4e3b\u8981\u533a\u522b<\/h3>\n<ol>\n<li>\u9875\u662f\u4fe1\u606f\u7684\u7269\u7406\u5355\u4f4d,\u5206\u9875\u662f\u4e3a\u4e86\u5b9e\u73b0\u975e\u8fde\u7eed\u5206\u914d,\u4ee5\u4fbf\u89e3\u51b3\u5185\u5b58\u788e\u7247\u95ee\u9898,\u6216\u8005\u8bf4\u5206\u9875\u662f\u7531\u4e8e\u7cfb\u7edf\u7ba1\u7406\u7684\u9700\u8981.\u6bb5\u662f\u4fe1\u606f\u7684\u903b\u8f91\u5355\u4f4d,\u5b83\u542b\u6709\u4e00\u7ec4\u610f\u4e49\u76f8\u5bf9\u5b8c\u6574\u7684\u4fe1\u606f,\u5206\u6bb5\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u66f4\u597d\u5730\u5b9e\u73b0\u5171\u4eab,\u6ee1\u8db3\u7528\u6237\u7684\u9700\u8981.<\/li>\n<li>\u9875\u7684\u5927\u5c0f\u56fa\u5b9a,\u7531\u7cfb\u7edf\u786e\u5b9a,\u5c06\u903b\u8f91\u5730\u5740\u5212\u5206\u4e3a\u9875\u53f7\u548c\u9875\u5185\u5730\u5740\u662f\u7531\u673a\u5668\u786c\u4ef6\u5b9e\u73b0\u7684.\u800c\u6bb5\u7684\u957f\u5ea6\u5374\u4e0d\u56fa\u5b9a,\u51b3\u5b9a\u4e8e\u7528\u6237\u6240\u7f16\u5199\u7684\u7a0b\u5e8f,\u901a\u5e38\u7531\u7f16\u8bd1\u7a0b\u5e8f\u5728\u5bf9\u6e90\u7a0b\u5e8f\u8fdb\u884c\u7f16\u8bd1\u65f6\u6839\u636e\u4fe1\u606f\u7684\u6027\u8d28\u6765\u5212\u5206.<\/li>\n<li>\u5206\u9875\u7684\u4f5c\u4e1a\u5730\u5740\u7a7a\u95f4\u662f\u4e00\u7ef4\u7684.\u5206\u6bb5\u7684\u5730\u5740\u7a7a\u95f4\u662f\u4e8c\u7ef4\u7684.<\/li>\n<\/ol>\n<h2>8 \u9875\u9762\u7f6e\u6362\u7b97\u6cd5<\/h2>\n<ol>\n<li>\u6700\u4f73\u7f6e\u6362\u7b97\u6cd5OPT:\u4e0d\u53ef\u80fd\u5b9e\u73b0<\/li>\n<li>\u5148\u8fdb\u5148\u51faFIFO<\/li>\n<li>\u6700\u8fd1\u6700\u4e45\u672a\u4f7f\u7528\u7b97\u6cd5LRU:\u6700\u8fd1\u4e00\u6bb5<br \/>\n\u65f6\u95f4\u91cc\u6700\u4e45\u6ca1\u6709\u4f7f\u7528\u8fc7\u7684\u9875\u9762\u4e88\u4ee5\u7f6e\u6362.<\/li>\n<li>clock\u7b97\u6cd5<\/li>\n<\/ol>\n<h2>9 \u8fb9\u6cbf\u89e6\u53d1\u548c\u6c34\u5e73\u89e6\u53d1<\/h2>\n<p>\u8fb9\u7f18\u89e6\u53d1\u662f\u6307\u6bcf\u5f53\u72b6\u6001\u53d8\u5316\u65f6\u53d1\u751f\u4e00\u4e2a io \u4e8b\u4ef6\uff0c\u6761\u4ef6\u89e6\u53d1\u662f\u53ea\u8981\u6ee1\u8db3\u6761\u4ef6\u5c31\u53d1\u751f\u4e00\u4e2a io \u4e8b\u4ef6<\/p>\n<h1>\u6570\u636e\u5e93<\/h1>\n<h2>1 \u4e8b\u52a1<\/h2>\n<p>\u6570\u636e\u5e93\u4e8b\u52a1(Database Transaction) \uff0c\u662f\u6307\u4f5c\u4e3a\u5355\u4e2a\u903b\u8f91\u5de5\u4f5c\u5355\u5143\u6267\u884c\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\uff0c\u8981\u4e48\u5b8c\u5168\u5730\u6267\u884c\uff0c\u8981\u4e48\u5b8c\u5168\u5730\u4e0d\u6267\u884c\u3002<\/p>\n<h2>2 \u6570\u636e\u5e93\u7d22\u5f15<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/tech.meituan.com\/mysql-index.html\">http:\/\/tech.meituan.com\/mysql-index.html<\/a><\/p>\n<p><a href=\"http:\/\/blog.codinglabs.org\/articles\/theory-of-mysql-index.html\">MySQL\u7d22\u5f15\u80cc\u540e\u7684\u6570\u636e\u7ed3\u6784\u53ca\u7b97\u6cd5\u539f\u7406<\/a><\/p>\n<p>\u805a\u96c6\u7d22\u5f15,\u975e\u805a\u96c6\u7d22\u5f15,B-Tree,B+Tree,\u6700\u5de6\u524d\u7f00\u539f\u7406<\/p>\n<h2>3 Redis\u539f\u7406<\/h2>\n<h2>4 \u4e50\u89c2\u9501\u548c\u60b2\u89c2\u9501<\/h2>\n<p>\u60b2\u89c2\u9501\uff1a\u5047\u5b9a\u4f1a\u53d1\u751f\u5e76\u53d1\u51b2\u7a81\uff0c\u5c4f\u853d\u4e00\u5207\u53ef\u80fd\u8fdd\u53cd\u6570\u636e\u5b8c\u6574\u6027\u7684\u64cd\u4f5c<\/p>\n<p>\u4e50\u89c2\u9501\uff1a\u5047\u8bbe\u4e0d\u4f1a\u53d1\u751f\u5e76\u53d1\u51b2\u7a81\uff0c\u53ea\u5728\u63d0\u4ea4\u64cd\u4f5c\u65f6\u68c0\u67e5\u662f\u5426\u8fdd\u53cd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/p>\n<h2>5 MVCC<\/h2>\n<h2>6 MyISAM\u548cInnoDB<\/h2>\n<p>MyISAM \u9002\u5408\u4e8e\u4e00\u4e9b\u9700\u8981\u5927\u91cf\u67e5\u8be2\u7684\u5e94\u7528\uff0c\u4f46\u5176\u5bf9\u4e8e\u6709\u5927\u91cf\u5199\u64cd\u4f5c\u5e76\u4e0d\u662f\u5f88\u597d\u3002\u751a\u81f3\u4f60\u53ea\u662f\u9700\u8981update\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6574\u4e2a\u8868\u90fd\u4f1a\u88ab\u9501\u8d77\u6765\uff0c\u800c\u522b\u7684\u8fdb\u7a0b\uff0c\u5c31\u7b97\u662f\u8bfb\u8fdb\u7a0b\u90fd\u65e0\u6cd5\u64cd\u4f5c\u76f4\u5230\u8bfb\u64cd\u4f5c\u5b8c\u6210\u3002\u53e6\u5916\uff0cMyISAM \u5bf9\u4e8e SELECT COUNT(*) \u8fd9\u7c7b\u7684\u8ba1\u7b97\u662f\u8d85\u5feb\u65e0\u6bd4\u7684\u3002<\/p>\n<p>InnoDB \u7684\u8d8b\u52bf\u4f1a\u662f\u4e00\u4e2a\u975e\u5e38\u590d\u6742\u7684\u5b58\u50a8\u5f15\u64ce\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u5c0f\u7684\u5e94\u7528\uff0c\u5b83\u4f1a\u6bd4 MyISAM \u8fd8\u6162\u3002\u4ed6\u662f\u5b83\u652f\u6301\u201c\u884c\u9501\u201d \uff0c\u4e8e\u662f\u5728\u5199\u64cd\u4f5c\u6bd4\u8f83\u591a\u7684\u65f6\u5019\uff0c\u4f1a\u66f4\u4f18\u79c0\u3002\u5e76\u4e14\uff0c\u4ed6\u8fd8\u652f\u6301\u66f4\u591a\u7684\u9ad8\u7ea7\u5e94\u7528\uff0c\u6bd4\u5982\uff1a\u4e8b\u52a1\u3002<\/p>\n<h1>\u7f51\u7edc<\/h1>\n<h2>1 \u4e09\u6b21\u63e1\u624b<\/h2>\n<ol>\n<li>\u5ba2\u6237\u7aef\u901a\u8fc7\u5411\u670d\u52a1\u5668\u7aef\u53d1\u9001\u4e00\u4e2aSYN\u6765\u521b\u5efa\u4e00\u4e2a\u4e3b\u52a8\u6253\u5f00\uff0c\u4f5c\u4e3a\u4e09\u8def\u63e1\u624b\u7684\u4e00\u90e8\u5206\u3002\u5ba2\u6237\u7aef\u628a\u8fd9\u6bb5\u8fde\u63a5\u7684\u5e8f\u53f7\u8bbe\u5b9a\u4e3a\u968f\u673a\u6570 A\u3002<\/li>\n<li>\u670d\u52a1\u5668\u7aef\u5e94\u5f53\u4e3a\u4e00\u4e2a\u5408\u6cd5\u7684SYN\u56de\u9001\u4e00\u4e2aSYN\/ACK\u3002ACK \u7684\u786e\u8ba4\u7801\u5e94\u4e3a A+1\uff0cSYN\/ACK \u5305\u672c\u8eab\u53c8\u6709\u4e00\u4e2a\u968f\u673a\u5e8f\u53f7 B\u3002<\/li>\n<li>\u6700\u540e\uff0c\u5ba2\u6237\u7aef\u518d\u53d1\u9001\u4e00\u4e2aACK\u3002\u5f53\u670d\u52a1\u7aef\u53d7\u5230\u8fd9\u4e2aACK\u7684\u65f6\u5019\uff0c\u5c31\u5b8c\u6210\u4e86\u4e09\u8def\u63e1\u624b\uff0c\u5e76\u8fdb\u5165\u4e86\u8fde\u63a5\u521b\u5efa\u72b6\u6001\u3002\u6b64\u65f6\u5305\u5e8f\u53f7\u88ab\u8bbe\u5b9a\u4e3a\u6536\u5230\u7684\u786e\u8ba4\u53f7 A+1\uff0c\u800c\u54cd\u5e94\u5219\u4e3a B+1\u3002<\/li>\n<\/ol>\n<h2>2 \u56db\u6b21\u6325\u624b<\/h2>\n<h2>3 ARP\u534f\u8bae<\/h2>\n<p>\u5730\u5740\u89e3\u6790\u534f\u8bae(Address Resolution Protocol): \u6839\u636eIP\u5730\u5740\u83b7\u53d6\u7269\u7406\u5730\u5740\u7684\u4e00\u4e2aTCP\/IP\u534f<\/p>\n<h2>4 urllib\u548curllib2\u7684\u533a\u522b<\/h2>\n<p>\u8fd9\u4e2a\u9762\u8bd5\u5b98\u786e\u5b9e\u95ee\u8fc7,\u5f53\u65f6\u7b54\u7684urllib2\u53ef\u4ee5Post\u800curllib\u4e0d\u53ef\u4ee5.<\/p>\n<ol>\n<li>urllib\u63d0\u4f9burlencode\u65b9\u6cd5\u7528\u6765GET\u67e5\u8be2\u5b57\u7b26\u4e32\u7684\u4ea7\u751f\uff0c\u800curllib2\u6ca1\u6709\u3002\u8fd9\u662f\u4e3a\u4f55urllib\u5e38\u548curllib2\u4e00\u8d77\u4f7f\u7528\u7684\u539f\u56e0\u3002<\/li>\n<li>urllib2\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2aRequest\u7c7b\u7684\u5b9e\u4f8b\u6765\u8bbe\u7f6eURL\u8bf7\u6c42\u7684headers\uff0curllib\u4ec5\u53ef\u4ee5\u63a5\u53d7URL\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4f60\u4e0d\u53ef\u4ee5\u4f2a\u88c5\u4f60\u7684User Agent\u5b57\u7b26\u4e32\u7b49\u3002<\/li>\n<\/ol>\n<h2>5 Post\u548cGet<\/h2>\n<h2>6 Cookie\u548cSession<\/h2>\n<h2>7 apache\u548cnginx\u7684\u533a\u522b<\/h2>\n<h2>8 \u7f51\u7ad9\u7528\u6237\u5bc6\u7801\u4fdd\u5b58<\/h2>\n<ol>\n<li>\u660e\u6587\u4fdd\u5b58<\/li>\n<li>\u660e\u6587hash\u540e\u4fdd\u5b58,\u5982md5<\/li>\n<li>MD5+Salt\u65b9\u5f0f,\u8fd9\u4e2asalt\u53ef\u4ee5\u968f\u673a<\/li>\n<li>\u77e5\u4e4e\u4f7f\u7528\u4e86Bcrypy(\u597d\u50cf)\u52a0\u5bc6<\/li>\n<\/ol>\n<h2>9 HTTP\u548cHTTPS<\/h2>\n<table>\n<thead>\n<tr>\n<th align=\"left\">\u72b6\u6001\u7801<\/th>\n<th align=\"left\">\u5b9a\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"left\">1xx \u62a5\u544a<\/td>\n<td align=\"left\">\u63a5\u6536\u5230\u8bf7\u6c42\uff0c\u7ee7\u7eed\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">2xx \u6210\u529f<\/td>\n<td align=\"left\">\u6b65\u9aa4\u6210\u529f\u63a5\u6536\uff0c\u88ab\u7406\u89e3\uff0c\u5e76\u88ab\u63a5\u53d7<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">3xx \u91cd\u5b9a\u5411<\/td>\n<td align=\"left\">\u4e3a\u4e86\u5b8c\u6210\u8bf7\u6c42,\u5fc5\u987b\u91c7\u53d6\u8fdb\u4e00\u6b65\u63aa\u65bd<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">4xx \u5ba2\u6237\u7aef\u51fa\u9519<\/td>\n<td align=\"left\">\u8bf7\u6c42\u5305\u62ec\u9519\u7684\u987a\u5e8f\u6216\u4e0d\u80fd\u5b8c\u6210<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">5xx \u670d\u52a1\u5668\u51fa\u9519<\/td>\n<td align=\"left\">\u670d\u52a1\u5668\u65e0\u6cd5\u5b8c\u6210\u663e\u7136\u6709\u6548\u7684\u8bf7\u6c42<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>403: Forbidden<br \/>404: Not Found<\/p>\n<p>HTTPS\u63e1\u624b,\u5bf9\u79f0\u52a0\u5bc6,\u975e\u5bf9\u79f0\u52a0\u5bc6,TLS\/SSL,RSA<\/p>\n<h2>10 XSRF\u548cXSS<\/h2>\n<ul>\n<li>CSRF(Cross-site request forgery)\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020<\/li>\n<li>XSS(Cross Site Scripting)\u8de8\u7ad9\u811a\u672c\u653b\u51fb<\/li>\n<\/ul>\n<p>CSRF\u91cd\u70b9\u5728\u8bf7\u6c42,XSS\u91cd\u70b9\u5728\u811a\u672c<\/p>\n<h2>11 \u5e42\u7b49 Idempotence<\/h2>\n<p>HTTP\u65b9\u6cd5\u7684\u5e42\u7b49\u6027\u662f\u6307\u4e00\u6b21\u548c\u591a\u6b21\u8bf7\u6c42\u67d0\u4e00\u4e2a\u8d44\u6e90\u5e94\u8be5\u5177\u6709\u540c\u6837\u7684<strong>\u526f\u4f5c\u7528<\/strong>\u3002(\u6ce8\u610f\u662f\u526f\u4f5c\u7528)<\/p>\n<p><code>GET http:\/\/www.bank.com\/account\/123456<\/code>\uff0c\u4e0d\u4f1a\u6539\u53d8\u8d44\u6e90\u7684\u72b6\u6001\uff0c\u4e0d\u8bba\u8c03\u7528\u4e00\u6b21\u8fd8\u662fN\u6b21\u90fd\u6ca1\u6709\u526f\u4f5c\u7528\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u5f3a\u8c03\u7684\u662f\u4e00\u6b21\u548cN\u6b21\u5177\u6709\u76f8\u540c\u7684\u526f\u4f5c\u7528\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21GET\u7684\u7ed3\u679c\u76f8\u540c\u3002<code>GET http:\/\/www.news.com\/latest-news<\/code>\u8fd9\u4e2aHTTP\u8bf7\u6c42\u53ef\u80fd\u4f1a\u6bcf\u6b21\u5f97\u5230\u4e0d\u540c\u7684\u7ed3\u679c\uff0c\u4f46\u5b83\u672c\u8eab\u5e76\u6ca1\u6709\u4ea7\u751f\u4efb\u4f55\u526f\u4f5c\u7528\uff0c\u56e0\u800c\u662f\u6ee1\u8db3\u5e42\u7b49\u6027\u7684\u3002<\/p>\n<p>DELETE\u65b9\u6cd5\u7528\u4e8e\u5220\u9664\u8d44\u6e90\uff0c\u6709\u526f\u4f5c\u7528\uff0c\u4f46\u5b83\u5e94\u8be5\u6ee1\u8db3\u5e42\u7b49\u6027\u3002\u6bd4\u5982\uff1a<code>DELETE http:\/\/www.forum.com\/article\/4231<\/code>\uff0c\u8c03\u7528\u4e00\u6b21\u548cN\u6b21\u5bf9\u7cfb\u7edf\u4ea7\u751f\u7684\u526f\u4f5c\u7528\u662f\u76f8\u540c\u7684\uff0c\u5373\u5220\u6389id\u4e3a4231\u7684\u5e16\u5b50\uff1b\u56e0\u6b64\uff0c\u8c03\u7528\u8005\u53ef\u4ee5\u591a\u6b21\u8c03\u7528\u6216\u5237\u65b0\u9875\u9762\u800c\u4e0d\u5fc5\u62c5\u5fc3\u5f15\u8d77\u9519\u8bef\u3002<\/p>\n<p>POST\u6240\u5bf9\u5e94\u7684URI\u5e76\u975e\u521b\u5efa\u7684\u8d44\u6e90\u672c\u8eab\uff0c\u800c\u662f\u8d44\u6e90\u7684\u63a5\u6536\u8005\u3002\u6bd4\u5982\uff1a<code>POST http:\/\/www.forum.com\/articles<\/code>\u7684\u8bed\u4e49\u662f\u5728<code>http:\/\/www.forum.com\/articles<\/code>\u4e0b\u521b\u5efa\u4e00\u7bc7\u5e16\u5b50\uff0cHTTP\u54cd\u5e94\u4e2d\u5e94\u5305\u542b\u5e16\u5b50\u7684\u521b\u5efa\u72b6\u6001\u4ee5\u53ca\u5e16\u5b50\u7684URI\u3002\u4e24\u6b21\u76f8\u540c\u7684POST\u8bf7\u6c42\u4f1a\u5728\u670d\u52a1\u5668\u7aef\u521b\u5efa\u4e24\u4efd\u8d44\u6e90\uff0c\u5b83\u4eec\u5177\u6709\u4e0d\u540c\u7684URI\uff1b\u6240\u4ee5\uff0cPOST\u65b9\u6cd5\u4e0d\u5177\u5907\u5e42\u7b49\u6027\u3002<\/p>\n<p>PUT\u6240\u5bf9\u5e94\u7684URI\u662f\u8981\u521b\u5efa\u6216\u66f4\u65b0\u7684\u8d44\u6e90\u672c\u8eab\u3002\u6bd4\u5982\uff1a<code>PUT http:\/\/www.forum\/articles\/4231<\/code>\u7684\u8bed\u4e49\u662f\u521b\u5efa\u6216\u66f4\u65b0ID\u4e3a4231\u7684\u5e16\u5b50\u3002\u5bf9\u540c\u4e00URI\u8fdb\u884c\u591a\u6b21PUT\u7684\u526f\u4f5c\u7528\u548c\u4e00\u6b21PUT\u662f\u76f8\u540c\u7684\uff1b\u56e0\u6b64\uff0cPUT\u65b9\u6cd5\u5177\u6709\u5e42\u7b49\u6027\u3002<\/p>\n<h2>12 RESTful\u67b6\u6784(SOAP,RPC)<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.ruanyifeng.com\/blog\/2011\/09\/restful.html\">http:\/\/www.ruanyifeng.com\/blog\/2011\/09\/restful.html<\/a><\/p>\n<h2>13 SOAP<\/h2>\n<p>SOAP\uff08\u539f\u4e3aSimple Object Access Protocol\u7684\u9996\u5b57\u6bcd\u7f29\u5199\uff0c\u5373\u7b80\u5355\u5bf9\u8c61\u8bbf\u95ee\u534f\u8bae\uff09\u662f\u4ea4\u6362\u6570\u636e\u7684\u4e00\u79cd\u534f\u8bae\u89c4\u8303\uff0c\u4f7f\u7528\u5728\u8ba1\u7b97\u673a\u7f51\u7edcWeb\u670d\u52a1\uff08web service\uff09\u4e2d\uff0c\u4ea4\u6362\u5e26\u7ed3\u6784\u4fe1\u606f\u3002SOAP\u4e3a\u4e86\u7b80\u5316\u7f51\u9875\u670d\u52a1\u5668\uff08Web Server\uff09\u4eceXML\u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u6570\u636e\u65f6\uff0c\u8282\u7701\u53bb\u683c\u5f0f\u5316\u9875\u9762\u65f6\u95f4\uff0c\u4ee5\u53ca\u4e0d\u540c\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u6309\u7167HTTP\u901a\u4fe1\u534f\u8bae\uff0c\u9075\u4eceXML\u683c\u5f0f\u6267\u884c\u8d44\u6599\u4e92\u6362\uff0c\u4f7f\u5176\u62bd\u8c61\u4e8e\u8bed\u8a00\u5b9e\u73b0\u3001\u5e73\u53f0\u548c\u786c\u4ef6\u3002<\/p>\n<h2>14 RPC<\/h2>\n<p>RPC\uff08Remote Procedure Call Protocol\uff09\u2014\u2014\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\u534f\u8bae\uff0c\u5b83\u662f\u4e00\u79cd\u901a\u8fc7\u7f51\u7edc\u4ece\u8fdc\u7a0b\u8ba1\u7b97\u673a\u7a0b\u5e8f\u4e0a\u8bf7\u6c42\u670d\u52a1\uff0c\u800c\u4e0d\u9700\u8981\u4e86\u89e3\u5e95\u5c42\u7f51\u7edc\u6280\u672f\u7684\u534f\u8bae\u3002RPC\u534f\u8bae\u5047\u5b9a\u67d0\u4e9b\u4f20\u8f93\u534f\u8bae\u7684\u5b58\u5728\uff0c\u5982TCP\u6216UDP\uff0c\u4e3a\u901a\u4fe1\u7a0b\u5e8f\u4e4b\u95f4\u643a\u5e26\u4fe1\u606f\u6570\u636e\u3002\u5728OSI\u7f51\u7edc\u901a\u4fe1\u6a21\u578b\u4e2d\uff0cRPC\u8de8\u8d8a\u4e86\u4f20\u8f93\u5c42\u548c\u5e94\u7528\u5c42\u3002RPC\u4f7f\u5f97\u5f00\u53d1\u5305\u62ec\u7f51\u7edc\u5206\u5e03\u5f0f\u591a\u7a0b\u5e8f\u5728\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u5bb9\u6613\u3002<\/p>\n<p>\u603b\u7ed3:\u670d\u52a1\u63d0\u4f9b\u7684\u4e24\u5927\u6d41\u6d3e.\u4f20\u7edf\u610f\u4e49\u4ee5\u65b9\u6cd5\u8c03\u7528\u4e3a\u5bfc\u5411\u901a\u79f0RPC\u3002\u4e3a\u4e86\u4f01\u4e1aSOA,\u82e5\u5e72\u5382\u5546\u8054\u5408\u63a8\u51fawebservice,\u5236\u5b9a\u4e86wsdl\u63a5\u53e3\u5b9a\u4e49,\u4f20\u8f93soap.\u5f53\u4e92\u8054\u7f51\u65f6\u4ee3,\u81c3\u80bfSOA\u88ab\u7b80\u5316\u4e3ahttp+xml\/json.\u4f46\u662f\u7b80\u5316\u51fa\u73b0\u5404\u79cd\u6df7\u4e71\u3002\u4ee5\u8d44\u6e90\u4e3a\u5bfc\u5411,\u4efb\u4f55\u64cd\u4f5c\u65e0\u975e\u662f\u5bf9\u8d44\u6e90\u7684\u589e\u5220\u6539\u67e5\uff0c\u4e8e\u662f\u7edf\u4e00\u7684REST\u51fa\u73b0\u4e86.<\/p>\n<p>\u8fdb\u5316\u7684\u987a\u5e8f: RPC -&gt; SOAP -&gt; RESTful<\/p>\n<h2>15 CGI\u548cWSGI<\/h2>\n<h2>16 \u4e2d\u95f4\u4eba\u653b\u51fb<\/h2>\n<p>\u5728GFW\u91cc\u5c61\u89c1\u4e0d\u9c9c\u7684,\u5475\u5475.<\/p>\n<p>\u4e2d\u95f4\u4eba\u653b\u51fb\uff08Man-in-the-middle attack\uff0c\u901a\u5e38\u7f29\u5199\u4e3aMITM\uff09\u662f\u6307\u653b\u51fb\u8005\u4e0e\u901a\u8baf\u7684\u4e24\u7aef\u5206\u522b\u521b\u5efa\u72ec\u7acb\u7684\u8054\u7cfb\uff0c\u5e76\u4ea4\u6362\u5176\u6240\u6536\u5230\u7684\u6570\u636e\uff0c\u4f7f\u901a\u8baf\u7684\u4e24\u7aef\u8ba4\u4e3a\u4ed6\u4eec\u6b63\u5728\u901a\u8fc7\u4e00\u4e2a\u79c1\u5bc6\u7684\u8fde\u63a5\u4e0e\u5bf9\u65b9\u76f4\u63a5\u5bf9\u8bdd\uff0c\u4f46\u4e8b\u5b9e\u4e0a\u6574\u4e2a\u4f1a\u8bdd\u90fd\u88ab\u653b\u51fb\u8005\u5b8c\u5168\u63a7\u5236\u3002<\/p>\n<h2>17 c10k\u95ee\u9898<\/h2>\n<p>\u6240\u8c13c10k\u95ee\u9898\uff0c\u6307\u7684\u662f\u670d\u52a1\u5668\u540c\u65f6\u652f\u6301\u6210\u5343\u4e0a\u4e07\u4e2a\u5ba2\u6237\u7aef\u7684\u95ee\u9898\uff0c\u4e5f\u5c31\u662fconcurrent 10 000 connection\uff08\u8fd9\u4e5f\u662fc10k\u8fd9\u4e2a\u540d\u5b57\u7684\u7531\u6765\uff09\u3002<\/p>\n<h2>18 socket<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.360doc.com\/content\/11\/0609\/15\/5482098_122692444.shtml\">http:\/\/www.360doc.com\/content\/11\/0609\/15\/5482098_122692444.shtml<\/a><\/p>\n<p>Socket=Ip address+ TCP\/UDP + port<\/p>\n<h2>19 \u6d4f\u89c8\u5668\u7f13\u5b58<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/www.cnblogs.com\/skynet\/archive\/2012\/11\/28\/2792503.html\">http:\/\/www.cnblogs.com\/skynet\/archive\/2012\/11\/28\/27<br \/>\n92503.html<\/a><\/p>\n<p>304 Not Modified<\/p>\n<h2>20 HTTP1.0\u548cHTTP1.1<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/blog.csdn.net\/elifefly\/article\/details\/3964766\">http:\/\/blog.csdn.net\/elifefly\/article\/details\/3964766<\/a><\/p>\n<ol>\n<li>\u8bf7\u6c42\u5934Host\u5b57\u6bb5,\u4e00\u4e2a\u670d\u52a1\u5668\u591a\u4e2a\u7f51\u7ad9<\/li>\n<li>\u957f\u94fe\u63a5<\/li>\n<li>\u6587\u4ef6\u65ad\u70b9\u7eed\u4f20<\/li>\n<li>\u8eab\u4efd\u8ba4\u8bc1,\u72b6\u6001\u7ba1\u7406,Cache\u7f13\u5b58<\/li>\n<\/ol>\n<h2>21 Ajax<\/h2>\n<h1>*NIX<\/h1>\n<h2>unix\u8fdb\u7a0b\u95f4\u901a\u4fe1\u65b9\u5f0f(IPC)<\/h2>\n<ol>\n<li>\u7ba1\u9053\uff08Pipe\uff09\uff1a\u7ba1\u9053\u53ef\u7528\u4e8e\u5177\u6709\u4eb2\u7f18\u5173\u7cfb\u8fdb\u7a0b\u95f4\u7684\u901a\u4fe1\uff0c\u5141\u8bb8\u4e00\u4e2a\u8fdb\u7a0b\u548c\u53e6\u4e00\u4e2a\u4e0e\u5b83\u6709\u5171\u540c\u7956\u5148\u7684\u8fdb\u7a0b\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1\u3002<\/li>\n<li>\u547d\u540d\u7ba1\u9053\uff08named pipe\uff09\uff1a\u547d\u540d\u7ba1\u9053\u514b\u670d\u4e86\u7ba1\u9053\u6ca1\u6709\u540d\u5b57\u7684\u9650\u5236\uff0c\u56e0\u6b64\uff0c\u9664\u5177\u6709\u7ba1\u9053\u6240\u5177\u6709\u7684\u529f\u80fd\u5916\uff0c\u5b83\u8fd8\u5141\u8bb8\u65e0\u4eb2\u7f18\u5173\u7cfb\u8fdb\u7a0b\u95f4\u7684\u901a\u4fe1\u3002\u547d\u540d\u7ba1\u9053\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6709\u5bf9\u5e94\u7684\u6587\u4ef6\u540d\u3002\u547d\u540d\u7ba1\u9053\u901a\u8fc7\u547d\u4ee4mkfifo\u6216\u7cfb\u7edf\u8c03\u7528mkfifo\u6765\u521b\u5efa\u3002<\/li>\n<li>\u4fe1\u53f7\uff08Signal\uff09\uff1a\u4fe1\u53f7\u662f\u6bd4\u8f83\u590d\u6742\u7684\u901a\u4fe1\u65b9\u5f0f\uff0c\u7528\u4e8e\u901a\u77e5\u63a5\u53d7\u8fdb\u7a0b\u6709\u67d0\u79cd\u4e8b\u4ef6\u53d1\u751f\uff0c\u9664\u4e86\u7528\u4e8e\u8fdb\u7a0b\u95f4\u901a\u4fe1\u5916\uff0c\u8fdb\u7a0b\u8fd8\u53ef\u4ee5\u53d1\u9001\u4fe1\u53f7\u7ed9\u8fdb\u7a0b\u672c\u8eab\uff1blinux\u9664\u4e86\u652f\u6301Unix\u65e9\u671f\u4fe1\u53f7\u8bed\u4e49\u51fd\u6570sigal\u5916\uff0c\u8fd8\u652f\u6301\u8bed\u4e49\u7b26\u5408Posix.1\u6807\u51c6\u7684\u4fe1\u53f7\u51fd\u6570sigaction\uff08\u5b9e\u9645\u4e0a\uff0c\u8be5\u51fd\u6570\u662f\u57fa\u4e8eBSD\u7684\uff0cBSD\u4e3a\u4e86\u5b9e\u73b0\u53ef\u9760\u4fe1\u53f7\u673a\u5236\uff0c\u53c8\u80fd\u591f\u7edf\u4e00\u5bf9\u5916\u63a5\u53e3\uff0c\u7528sigaction\u51fd\u6570\u91cd\u65b0\u5b9e\u73b0\u4e86signal\u51fd\u6570\uff09\u3002<\/li>\n<li>\u6d88\u606f\uff08Message\uff09\u961f\u5217\uff1a\u6d88\u606f\u961f\u5217\u662f\u6d88\u606f\u7684\u94fe\u63a5\u8868\uff0c\u5305\u62ecPosix\u6d88\u606f\u961f\u5217system V\u6d88\u606f\u961f\u5217\u3002\u6709\u8db3\u591f\u6743\u9650\u7684\u8fdb\u7a0b\u53ef\u4ee5\u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u6d88\u606f\uff0c\u88ab\u8d4b\u4e88\u8bfb\u6743\u9650\u7684\u8fdb\u7a0b\u5219\u53ef\u4ee5\u8bfb\u8d70\u961f\u5217\u4e2d\u7684\u6d88\u606f\u3002\u6d88\u606f\u961f\u5217\u514b\u670d\u4e86\u4fe1\u53f7\u627f\u8f7d\u4fe1\u606f\u91cf\u5c11\uff0c\u7ba1\u9053\u53ea\u80fd\u627f\u8f7d\u65e0\u683c\u5f0f\u5b57\u8282\u6d41\u4ee5\u53ca\u7f13\u51b2\u533a\u5927\u5c0f\u53d7\u9650\u7b49\u7f3a<\/li>\n<li>\u5171\u4eab\u5185\u5b58\uff1a\u4f7f\u5f97\u591a\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u540c\u4e00\u5757\u5185\u5b58\u7a7a\u95f4\uff0c\u662f\u6700\u5feb\u7684\u53ef\u7528IPC\u5f62\u5f0f\u3002\u662f\u9488\u5bf9\u5176\u4ed6\u901a\u4fe1\u673a\u5236\u8fd0\u884c\u6548\u7387\u8f83\u4f4e\u800c\u8bbe\u8ba1\u7684\u3002\u5f80\u5f80\u4e0e\u5176\u5b83\u901a\u4fe1\u673a\u5236\uff0c\u5982\u4fe1\u53f7\u91cf\u7ed3\u5408\u4f7f\u7528\uff0c\u6765\u8fbe\u5230\u8fdb\u7a0b\u95f4\u7684\u540c\u6b65\u53ca\u4e92\u65a5\u3002<\/li>\n<li>\u5185\u5b58\u6620\u5c04\uff08mapped memory\uff09\uff1a\u5185\u5b58\u6620\u5c04\u5141\u8bb8\u4efb\u4f55\u591a\u4e2a\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff0c\u6bcf\u4e00\u4e2a\u4f7f\u7528\u8be5\u673a\u5236\u7684\u8fdb\u7a0b\u901a\u8fc7\u628a\u4e00\u4e2a\u5171\u4eab\u7684\u6587\u4ef6\u6620\u5c04\u5230\u81ea\u5df1\u7684\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u6765\u5b9e\u73b0\u5b83\u3002<\/li>\n<li>\u4fe1\u53f7\u91cf\uff08semaphore\uff09\uff1a\u4e3b\u8981\u4f5c\u4e3a\u8fdb\u7a0b\u95f4\u4ee5\u53ca\u540c\u4e00\u8fdb\u7a0b\u4e0d\u540c\u7ebf\u7a0b\u4e4b\u95f4\u7684\u540c\u6b65\u624b\u6bb5\u3002<\/li>\n<li>\u5957\u63a5\u53e3\uff08Socket\uff09\uff1a\u66f4\u4e3a\u4e00\u822c\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1\u673a\u5236\uff0c\u53ef\u7528\u4e8e\u4e0d\u540c\u673a\u5668\u4e4b\u95f4\u7684\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002\u8d77\u521d\u662f\u7531Unix\u7cfb\u7edf\u7684BSD\u5206\u652f\u5f00\u53d1\u51fa\u6765\u7684\uff0c\u4f46\u73b0\u5728\u4e00\u822c\u53ef\u4ee5\u79fb\u690d\u5230\u5176\u5b83\u7c7bUnix\u7cfb\u7edf\u4e0a\uff1aLinux\u548cSystem V\u7684\u53d8\u79cd\u90fd\u652f\u6301\u5957\u63a5\u5b57\u3002<\/li>\n<\/ol>\n<h1>\u6570\u636e\u7ed3\u6784<\/h1>\n<h2>1 \u7ea2\u9ed1\u6811<\/h2>\n<p>\u7ea2\u9ed1\u6811\u4e0eAVL\u7684\u6bd4\u8f83\uff1a<\/p>\n<p>AVL\u662f\u4e25\u683c\u5e73\u8861\u6811\uff0c\u56e0\u6b64\u5728\u589e\u52a0\u6216\u8005\u5220\u9664\u8282\u70b9\u7684\u65f6\u5019\uff0c\u6839\u636e\u4e0d\u540c\u60c5\u51b5\uff0c\u65cb\u8f6c\u7684\u6b21\u6570\u6bd4\u7ea2\u9ed1\u6811\u8981\u591a\uff1b<\/p>\n<p>\u7ea2\u9ed1\u662f\u7528\u975e\u4e25\u683c\u7684\u5e73\u8861\u6765\u6362\u53d6\u589e\u5220\u8282\u70b9\u65f6\u5019\u65cb\u8f6c\u6b21\u6570\u7684\u964d\u4f4e\uff1b<\/p>\n<p>\u6240\u4ee5\u7b80\u5355\u8bf4\uff0c\u5982\u679c\u4f60\u7684\u5e94\u7528\u4e2d\uff0c\u641c\u7d22\u7684\u6b21\u6570\u8fdc\u8fdc\u5927\u4e8e\u63d2\u5165\u548c\u5220\u9664\uff0c\u90a3\u4e48\u9009\u62e9AVL\uff0c\u5982\u679c\u641c\u7d22\uff0c\u63d2\u5165\u5220\u9664\u6b21\u6570\u51e0\u4e4e\u5dee\u4e0d\u591a\uff0c\u5e94\u8be5\u9009\u62e9RB\u3002<\/p>\n<h1>\u7f16\u7a0b\u9898<\/h1>\n<h2>1 \u53f0\u9636\u95ee\u9898\/\u6590\u6ce2\u7eb3\u6308<\/h2>\n<p>\u4e00\u53ea\u9752\u86d9\u4e00\u6b21\u53ef\u4ee5\u8df3\u4e0a1\u7ea7\u53f0\u9636\uff0c\u4e5f\u53ef\u4ee5\u8df3\u4e0a2\u7ea7\u3002\u6c42\u8be5\u9752\u86d9\u8df3\u4e0a\u4e00\u4e2an\u7ea7\u7684\u53f0\u9636\u603b\u5171\u6709\u591a\u5c11\u79cd\u8df3\u6cd5\u3002<\/p>\n<pre><code class=\"lang-python\">fib = lambda n: 1 if n &lt;= 2 else fib(n - 1) + fib(n - 2)<\/code><\/pre>\n<p>\u7b2c\u4e8c\u79cd\u8bb0\u5fc6\u65b9\u6cd5<\/p>\n<pre><code class=\"lang-python\">def memo(func):\n    cache={}\n    def wrap(*args):\n        if args not in cache:\n            cache[args]=func(*args)\n        return cache[args]\n    return wrap\n\n@memo\ndef fib(i):\n    if i&lt;2:\n        return 1\n    return fib(i-1)+fib(i-2)<\/code><\/pre>\n<p>\u7b2c\u4e09\u79cd\u65b9\u6cd5<\/p>\n<pre><code class=\"lang-python\">def fib(n):\n    a, b = 0, 1\n    while a &lt; n:\n        print a,\n        a, b  = b, a + b\n    print\nfib(1000)<\/code><\/pre>\n<h2>2 \u53d8\u6001\u53f0\u9636\u95ee\u9898<\/h2>\n<p>\u4e00\u53ea\u9752\u86d9\u4e00\u6b21\u53ef\u4ee5\u8df3\u4e0a1\u7ea7\u53f0\u9636\uff0c\u4e5f\u53ef\u4ee5\u8df3\u4e0a2\u7ea7\u2026\u2026\u5b83\u4e5f\u53ef\u4ee5\u8df3\u4e0an\u7ea7\u3002\u6c42\u8be5\u9752\u86d9\u8df3\u4e0a\u4e00\u4e2an\u7ea7\u7684\u53f0\u9636\u603b\u5171\u6709\u591a\u5c11\u79cd\u8df3\u6cd5\u3002<\/p>\n<pre><code class=\"lang-python\">fib = lambda n: i if n &lt; 2 else 2 * fib(n - 1)<\/code><\/pre>\n<h2>3 \u77e9\u5f62\u8986\u76d6<\/h2>\n<p>\u6211\u4eec\u53ef\u4ee5\u7528<code>2*1<\/code>\u7684\u5c0f\u77e9\u5f62\u6a2a\u7740\u6216\u8005\u7ad6\u7740\u53bb\u8986\u76d6\u66f4\u5927\u7684\u77e9\u5f62\u3002\u8bf7\u95ee\u7528n\u4e2a<code>2*1<\/code>\u7684\u5c0f\u77e9\u5f62\u65e0\u91cd\u53e0\u5730\u8986\u76d6\u4e00\u4e2a<code>2*n<\/code>\u7684\u5927\u77e9\u5f62\uff0c\u603b\u5171\u6709\u591a\u5c11\u79cd\u65b9\u6cd5\uff1f<\/p>\n<blockquote><p>\u7b2c<code>2*n<\/code>\u4e2a\u77e9\u5f62\u7684\u8986\u76d6\u65b9\u6cd5\u7b49\u4e8e\u7b2c<code>2*(n-1)<\/code>\u52a0\u4e0a\u7b2c<code>2*(n-2)<\/code>\u7684\u65b9\u6cd5\u3002<\/p><\/blockquote>\n<pre><code class=\"lang-python\">f = lambda n: 1 if n &lt; 2 else f(n - 1) + f(n - 2)<\/code><\/pre>\n<h2>4 \u6768\u6c0f\u77e9\u9635\u67e5\u627e<\/h2>\n<p>\u5728\u4e00\u4e2am\u884cn\u5217\u4e8c\u7ef4\u6570\u7ec4\u4e2d\uff0c\u6bcf\u4e00\u884c\u90fd\u6309\u7167\u4ece\u5de6\u5230\u53f3\u9012\u589e\u7684\u987a\u5e8f\u6392\u5e8f\uff0c\u6bcf\u4e00\u5217\u90fd\u6309\u7167\u4ece\u4e0a\u5230\u4e0b\u9012\u589e\u7684\u987a\u5e8f\u6392\u5e8f\u3002\u8bf7\u5b8c\u6210\u4e00\u4e2a\u51fd\u6570\uff0c\u8f93\u5165\u8fd9\u6837\u7684\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u548c\u4e00\u4e2a\u6574\u6570\uff0c\u5224\u65ad\u6570\u7ec4\u4e2d\u662f\u5426\u542b\u6709\u8be5\u6574\u6570\u3002<\/p>\n<h2>5 \u53bb\u9664\u5217\u8868\u4e2d\u7684\u91cd\u590d\u5143\u7d20<\/h2>\n<p>\u7528\u96c6\u5408<\/p>\n<pre><code class=\"lang-python\">list(set(l))<\/code><\/pre>\n<p>\u7528\u5b57\u5178<\/p>\n<pre><code class=\"lang-python\">l1 = ['b','c','d','b','c','a','a']\nl2 = {}.fromkeys(l1).keys()\nprint l2<\/code><\/pre>\n<p>\u7528\u5b57\u5178\u5e76\u4fdd\u6301\u987a\u5e8f<\/p>\n<pre><code class=\"lang-python\">l1 = ['b','c','d','b','c','a','a']\nl2 = list(set(l1))\nl2.sort(key=l1.index)\nprint l2<\/code><\/pre>\n<p>\u5217\u8868\u63a8\u5bfc\u5f0f<\/p>\n<pre><code class=\"lang-python\">l1 = ['b','c','d','b','c','a','a']\nl2 = []\n[l2.append(i) for i in l1 if not i in l2]<\/code><\/pre>\n<p>\u9762\u8bd5\u5b98\u63d0\u5230\u7684,\u5148\u6392\u5e8f\u7136\u540e\u5220\u9664.<\/p>\n<h2>6 \u94fe\u8868\u6210\u5bf9\u8c03\u6362<\/h2>\n<p><code>1-&gt;2-&gt;3-&gt;4<\/code>\u8f6c\u6362\u6210<code>2-&gt;1-&gt;4-&gt;3<\/code>.<\/p>\n<pre><code class=\"lang-python\">class ListNode:\n    def __init__(self, x):\n        self.val = x\n        self.next = None\n\nclass Solution:\n    # @param a ListNode\n    # @return a ListNode\n    def swapPairs(self, head):\n        if head != None and head.next != None:\n            next = head.next\n            head.next = self.swapPairs(next.next)\n            next.next = head\n            return next\n        return head<\/code><\/pre>\n<h2>7 \u521b\u5efa\u5b57\u5178\u7684\u65b9\u6cd5<\/h2>\n<h3>1 \u76f4\u63a5\u521b\u5efa<\/h3>\n<pre><code class=\"lang-python\">dict = {'name':'earth', 'port':'80'}<\/code><\/pre>\n<h3>2 \u5de5\u5382\u65b9\u6cd5<\/h3>\n<pre><code class=\"lang-python\">items=[('name','earth'),('port','80')]\ndict2=dict(items)\ndict1=dict((['name','earth'],['port','80']))<\/code><\/pre>\n<h3>3 fromkeys()\u65b9\u6cd5<\/h3>\n<pre><code class=\"lang-python\">dict1={}.fromkeys(('x','y'),-1)\ndict={'x':-1,'y':-1}\ndict2={}.fromkeys(('x','y'))\ndict2={'x':None, 'y':None}<\/code><\/pre>\n<h2>8 \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u5217\u8868<\/h2>\n<p>\u77e5\u4e4e\u8fdc\u7a0b\u9762\u8bd5\u8981\u6c42\u7f16\u7a0b<\/p>\n<p>\u5c3e\u9012\u5f52<\/p>\n<pre><code class=\"lang-python\">def _recursion_merge_sort2(l1, l2, tmp):\n    if len(l1) == 0 or len(l2) == 0:\n        tmp.extend(l1)\n        tmp.extend(l2)\n        return tmp\n    else:\n        if l1[0] &lt; l2[0]:\n            tmp.append(l1[0])\n            del l1[0]\n        else:\n            tmp.append(l2[0])\n            del l2[0]\n        return _recursion_merge_sort2(l1, l2, tmp)\n\ndef recursion_merge_sort2(l1, l2):\n    return _recursion_merge_sort2(l1, l2, [])<\/code><\/pre>\n<p>\u5faa\u73af\u7b97\u6cd5<\/p>\n<pre><code class=\"lang-pyhton\">def loop_merge_sort(l1, l2):\n    tmp = []\n    while len(l1) &gt; 0 and len(l2) &gt; 0:\n        if l1[0] &lt; l2[0]:\n            tmp.append(l1[0])\n            del l1[0]\n        else:\n            tmp.append(l2[0])\n            del l2[0]\n    tmp.extend(l1)\n    tmp.extend(l2)\n    return tmp<\/code><\/pre>\n<h2>9 \u4ea4\u53c9\u94fe\u8868\u6c42\u4ea4\u70b9<\/h2>\n<p>\u53bb\u54ea\u513f\u7684\u9762\u8bd5,\u6ca1\u505a\u51fa\u6765.<\/p>\n<pre><code class=\"lang-python\">class ListNode:\n    def __init__(self, x):\n        self.val = x\n        self.next = None\ndef node(l1, l2):\n    length1, lenth2 = 0, 0\n    # \u6c42\u4e24\u4e2a\u94fe\u8868\u957f\u5ea6\n    while l1.next:\n        l1 = l1.next\n        length1 += 1\n    while l2.next:\n        l2 = l2.next\n        length2 += 1\n    # \u957f\u7684\u94fe\u8868\u5148\u8d70\n    if length1 &gt; lenth2:\n        for _ in range(length1 - length2):\n            l1 = l1.next\n    else:\n        for _ in range(length2 - length1):\n            l2 = l2.next\n    while l1 and l2:\n        if l1.next == l2.next:\n            return l1.next\n        else:\n            l1 = l1.next\n            l2 = l2.next<\/code><\/pre>\n<h2>10 \u4e8c\u5206\u67e5\u627e<\/h2>\n<pre><code class=\"lang-python\">def binarySearch(l, t):\n    low, high = 0, len(l) - 1\n    while low &lt; high:\n        print low, high\n        mid = (low + high) \/ 2\n        if l[mid] &gt; t:\n            high = mid\n        elif l[mid] &lt; t:\n            low = mid + 1\n        else:\n            return mid\n    return False\n\nif __name__ == '__main__':\n    l = [1, 4, 12, 45, 66, 99, 120, 444]\n    print binarySearch(l, 12)\n    print binarySearch(l, 1)\n    print binarySearch(l, 13)<\/code><\/pre>\n<h2>11 \u5feb\u6392<\/h2>\n<pre><code class=\"lang-python\">def qsort(seq):\n    if seq==[]:\n        return []\n    else:\n        pivot=seq[0]\n        lesser=qsort([x for x in seq[1:] if x&lt;pivot])\n        greater=qsort([x for x in seq[1:] if x&gt;=pivot])\n        return lesser+[pivot]+greater\n\nif __name__=='__main__':\n    seq=[5,6,78,9,0,-1,2,3,-65,12]\n    print(qsort(seq))<\/code><\/pre>\n<h2>12 \u627e\u96f6\u95ee\u9898<\/h2>\n<pre><code class=\"lang-python\">def  coinChange(values, money, coinsUsed):\n    #values    T[1:n]\u6570\u7ec4\n    #valuesCounts   \u94b1\u5e01\u5bf9\u5e94\u7684\u79cd\u7c7b\u6570\n    #money  \u627e\u51fa\u6765\u7684\u603b\u94b1\u6570\n    #coinsUsed   \u5bf9\u5e94\u4e8e\u76ee\u524d\u94b1\u5e01\u603b\u6570i\u6240\u4f7f\u7528\u7684\u786c\u5e01\u6570\u76ee\n    for cents in range(1, money+1):\n        minCoins = cents     #\u4ece\u7b2c\u4e00\u4e2a\u5f00\u59cb\u5230money\u7684\u6240\u6709\u60c5\u51b5\u521d\u59cb\n        for value in values:\n            if value &lt;= cents:\n                temp = coinsUsed[cents - value] + 1\n                if temp &lt; minCoins:\n                    minCoins = temp\n        coinsUsed[cents] = minCoins\n        print('\u9762\u503c\u4e3a\uff1a{0} \u7684\u6700\u5c0f\u786c\u5e01\u6570\u76ee\u4e3a\uff1a{1} '.format(cents, coinsUsed[cents]) )\n\nif __name__ == '__main__':\n    values = [ 25, 21, 10, 5, 1]\n    money = 63\n    coinsUsed = {i:0 for i in range(money+1)}\n    coinChange(values, money, coinsUsed)<\/code><\/pre>\n<h2>13 \u5e7f\u5ea6\u904d\u5386\u548c\u6df1\u5ea6\u904d\u5386\u4e8c\u53c9\u6811<\/h2>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4\uff0c\u6784\u5efa\u4e8c\u53c9\u6811\uff0c\u5e76\u4e14\u6309\u5c42\u6b21\u6253\u5370\u8fd9\u4e2a\u4e8c\u53c9\u6811<\/p>\n<pre><code class=\"lang-python\">## 14 \u4e8c\u53c9\u6811\u8282\u70b9\nclass Node(object):\n    def __init__(self, data, left=None, right=None):\n        self.data = data\n        self.left = left\n        self.right = right\n\ntree = Node(1, Node(3, Node(7, Node(0)), Node(6)), Node(2, Node(5), Node(4)))\n\n## 15 \u5c42\u6b21\u904d\u5386\ndef lookup(root):\n    stack = [root]\n    while stack:\n        current = stack.pop(0)\n        print current.data\n        if current.left:\n            stack.append(current.left)\n        if current.right:\n            stack.append(current.right)\n## 16 \u6df1\u5ea6\u904d\u5386\ndef deep(root):\n    if not root:\n        return\n    print root.data\n    deep(root.left)\n    deep(root.right)\n\nif __name__ == '__main__':\n    lookup(tree)\n    deep(tree)<\/code><\/pre>\n<h2>17 \u524d\u4e2d\u540e\u5e8f\u904d\u5386<\/h2>\n<p>\u6df1\u5ea6\u904d\u5386\u6539\u53d8\u987a\u5e8f\u5c31OK\u4e86<\/p>\n<h2>18 \u6c42\u6700\u5927\u6811\u6df1<\/h2>\n<pre><code class=\"lang-python\">def maxDepth(root):\n        if not root:\n            return 0\n        return max(maxDepth(root.left), maxDepth(root.right)) + 1<\/code><\/pre>\n<h2>19 \u6c42\u4e24\u68f5\u6811\u662f\u5426\u76f8\u540c<\/h2>\n<pre><code class=\"lang-python\">def isSameTree(p, q):\n    if p == None and q == None:\n        return True\n    elif p and q :\n        return p.val == q.val and isSameTree(p.left,q.left) and isSameTree(p.right,q.right)\n    else :\n        return False<\/code><\/pre>\n<h2>20 \u524d\u5e8f\u4e2d\u5e8f\u6c42\u540e\u5e8f<\/h2>\n<p>\u63a8\u8350: <a href=\"http:\/\/blog.csdn.net\/hinyunsin\/article\/details\/6315502\">http:\/\/blog.csdn.net\/hinyunsin\/article\/details\/6315502<\/a><\/p>\n<pre><code class=\"lang-python\">def rebuild(pre, center):\n    if not pre:\n        return\n    cur = Node(pre[0])\n    index = center.index(pre[0])\n    cur.left = rebuild(pre[1:index + 1], center[:index])\n    cur.right = rebuild(pre[index + 1:], center[index + 1:])\n    return cur\n\ndef deep(root):\n    if not root:\n        return\n    deep(root.left)\n    deep(root.right)\n    print root.data<\/code><\/pre>\n<h2>21 \u5355\u94fe\u8868\u9006\u7f6e<\/h2>\n<pre><code class=\"lang-python\">class Node(object):\n    def __init__(self, data=None, next=None):\n        self.data = data\n        self.next = next\n\nlink = Node(1, Node(2, Node(3, Node(4, Node(5, Node(6, Node(7, Node(8, Node(9)))))))))\n\ndef rev(link):\n    pre = link\n    cur = link.next\n    pre.next = None\n    while cur:\n        tmp = cur.next\n        cur.next = pre\n        pre = cur\n        cur = tmp\n    return pre\n\nroot = rev(link)\nwhile root:\n    print root.data\n    root = root.next<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents Python\u8bed\u8a00\u7279\u6027 1 Python\u7684\u51fd\u6570\u53c2\u6570\u4f20\u9012 2 Pyt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[45],"class_list":["post-819","post","type-post","status-publish","format-standard","hentry","category-learn","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=819"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/819\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}