﻿{"id":52,"date":"2020-02-20T21:50:59","date_gmt":"2020-02-20T13:50:59","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=52"},"modified":"2020-02-21T18:10:15","modified_gmt":"2020-02-21T10:10:15","slug":"python-bibao-renshi","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/python-bibao-renshi.html","title":{"rendered":"Python\u95ed\u5305\u521d\u6b65\u8ba4\u8bc6"},"content":{"rendered":"<p>\u95ed\u5305\u5e76\u4e0d\u53ea\u662f\u4e00\u4e2aPython\u4e2d\u7684\u6982\u5ff5\uff0c\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5e94\u7528\u8f83\u4e3a\u5e7f\u6cdb\u3002\u7406\u89e3Python\u4e2d\u7684\u95ed\u5305\u4e00\u65b9\u9762\u662f\u80fd\u591f\u6b63\u786e\u7684\u4f7f\u7528\u95ed\u5305\uff0c\u53e6\u4e00\u65b9\u9762\u53ef\u4ee5\u597d\u597d\u4f53\u4f1a\u548c\u601d\u8003\u95ed\u5305\u7684\u8bbe\u8ba1\u601d\u60f3\u3002<\/p>\n<p>\u8981\u7406\u89e3Python\u95ed\u5305\uff0c\u5148\u8981\u4e86\u89e3Python\u4e2d\u7684\u53d8\u91cf\u4f5c\u7528\u57df\u89c4\u5219\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-85\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-45-03.png\" alt=\"\" width=\"735\" height=\"468\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-45-03.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-45-03-300x191.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<h3>\u53d8\u91cf\u4f5c\u7528\u57df\u89c4\u5219<\/h3>\n<p>\u9996\u5148\uff0c\u5728\u51fd\u6570\u4e2d\u662f\u80fd\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\u7684\uff1a<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">[linuxmi@linux:~]$ python3\r\nPython <span style=\"color: #b65611;\">3.6<\/span><span style=\"color: #b65611;\">.9<\/span> (<span style=\"color: #b854d4;\">default<\/span>, Nov  <span style=\"color: #b65611;\">7<\/span> <span style=\"color: #b65611;\">2019<\/span>, <span style=\"color: #b65611;\">10<\/span>:<span style=\"color: #b65611;\">44<\/span>:<span style=\"color: #b65611;\">02<\/span>)  \r\n[GCC <span style=\"color: #b65611;\">8.3<\/span><span style=\"color: #b65611;\">.0<\/span>] on linux\r\nType <span style=\"color: #60ac39;\">\"help\"<\/span>, <span style=\"color: #60ac39;\">\"copyright\"<\/span>, <span style=\"color: #60ac39;\">\"credits\"<\/span> or <span style=\"color: #60ac39;\">\"license\"<\/span> <span style=\"color: #b854d4;\">for<\/span>  more information.\r\n&gt;&gt;&gt; i = <span style=\"color: #60ac39;\">'www.linuxmi.com'<\/span>\r\n&gt;&gt;&gt; def  foo():\r\n...      print(i)\r\n... \r\n&gt;&gt;&gt;  foo()\r\nwww.linuxmi.com\r\n&gt;&gt;&gt;\r\n<\/code><\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-80\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-13-30.png\" alt=\"\" width=\"735\" height=\"270\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-13-30.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-13-30-300x110.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>\u7136\u540e\uff0c\u5728\u4e00\u4e2a\u5d4c\u5957\u51fd\u6570\u4e2d\uff0c\u5185\u5c42\u51fd\u6570\u80fd\u591f\u8bbf\u95ee\u5728\u5916\u5c42\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u5c40\u90e8\u53d8\u91cf\uff1a<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">&gt;&gt;&gt; def foo():\r\n...     i = <span style=\"color: #60ac39;\">'linuxmi.com'<\/span>\r\n...     def  bar():\r\n...         print(i)\r\n...     <span style=\"color: #b854d4;\">return<\/span> bar\r\n... \r\n&gt;&gt;&gt;  foo()()\r\nlinuxmi.com\r\n<\/code><\/pre>\n<\/div>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-81\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-20-06.png\" alt=\"\" width=\"735\" height=\"198\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-20-06.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-20-06-300x81.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/h3>\n<h3>\u95ed\u5305<\/h3>\n<p>\u4e0a\u9762\u7684\u5d4c\u5957\u51fd\u6570\u5c31\u662f\u95ed\u5305\u3002<strong>\u95ed\u5305<\/strong>\u662f\u6307\u5ef6\u4f38\u4e86\u4f5c\u7528\u57df\u7684\u51fd\u6570\uff0c\u5728\u5176\u4e2d\u80fd\u591f\u8bbf\u95ee\u672a\u5728\u51fd\u6570\u5b9a\u4e49\u4f53\u4e2d\u5b9a\u4e49\u7684\u975e\u5168\u5c40\u53d8\u91cf\u3002\u672a\u5728\u51fd\u6570\u5b9a\u4e49\u4f53\u4e2d\u5b9a\u4e49\u7684\u975e\u5168\u5c40\u53d8\u91cf\u4e00\u822c\u90fd\u662f\u5728\u5d4c\u5957\u51fd\u6570\u4e2d\u51fa\u73b0\u7684\u3002<\/p>\n<p>\u4e0a\u8ff0\u793a\u4f8b\u4e2d\u7684\u53d8\u91cfi\u5c31\u662f\u4e00\u4e2a\u5e76\u672a\u5728\u51fd\u6570bar\u4e2d\u5b9a\u4e49\u7684\u975e\u5168\u5c40\u53d8\u91cf\u3002\u5bf9\u4e8ebar\u6765\u8bf4\uff0c\u5b83\u6709\u4e2a\u4e13\u4e1a\u540d\u5b57\uff0c\u53eb\u505a<strong>\u81ea\u7531\u53d8\u91cf<\/strong>\u3002<\/p>\n<p>\u81ea\u7531\u53d8\u91cf\u7684\u540d\u79f0\u53ef\u4ee5\u5728\u5b57\u8282\u7801\u5bf9\u8c61\u4e2d\u67e5\u770b\uff1a<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">&gt;&gt;&gt; bar = foo()\r\n&gt;&gt;&gt; bar.__code__.co_freevars\r\n(<span style=\"color: #60ac39;\">'i'<\/span>,)\r\n<\/code><\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-82\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-21-09.png\" alt=\"\" width=\"735\" height=\"252\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-21-09.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-21-09-300x103.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/>\u81ea\u7531\u53d8\u91cf\u7684\u503c\u7ed1\u5b9a\u5728\u51fd\u6570\u7684__closure__\u5c5e\u6027\u4e2d\uff1a<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">&gt;&gt;&gt; bar.__closure__\r\n(<span style=\"color: #d73737;\">&lt;cell at 0x7fc04b2ae288: str object at  0x7fc0472efa30&gt;<\/span>,)\r\n<\/code><\/pre>\n<\/div>\n<p>\u5176\u4e2d\u4fdd\u5b58\u4e86\u5bf9\u5e94\u81ea\u7531\u53d8\u91cf\u7684cell\u5bf9\u8c61\u7684\u5e8f\u5217\uff0ccell\u5bf9\u8c61\u7684cell_contents\u5c5e\u6027\u4fdd\u5b58\u4e86\u53d8\u91cf\u7684\u503c\uff1a<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">&gt;&gt;&gt; bar.__closure__[<span style=\"color: #b65611;\">0<\/span>].cell_contents\r\n<span style=\"color: #60ac39;\">'linuxmi.com'<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-83\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-22-10.png\" alt=\"\" width=\"735\" height=\"90\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-22-10.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-22-10-300x37.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/strong><\/p>\n<p><strong>\u95ed\u5305\u7684\u683c\u5f0f<\/strong><\/p>\n<p>\u4e0b\u9762\u7528\u4f2a\u4ee3\u7801\u8fdb\u884c\u95ed\u5305\u683c\u5f0f\u7684\u63cf\u8ff0<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">def \u5916\u5c42\u51fd\u6570(\u53c2\u6570):\r\n    def \u5185\u5c42\u51fd\u6570():\r\n        print(<span style=\"color: #60ac39;\">\"\u5185\u5c42\u51fd\u6570\u6267\u884c\"<\/span>, \u53c2\u6570)\r\n\r\n    <span style=\"color: #b854d4;\">return<\/span> \u5185\u5c42\u51fd\u6570\r\n\r\n\u5185\u5c42\u51fd\u6570\u7684\u5f15\u7528 = \u5916\u5c42\u51fd\u6570(<span style=\"color: #60ac39;\">\"\u4f20\u5165\u53c2\u6570\"<\/span>)\r\n\u5185\u5c42\u51fd\u6570\u7684\u5f15\u7528()\r\n<\/code><\/pre>\n<\/div>\n<p>\u5916\u5c42\u51fd\u6570\u4e2d\u7684\u53c2\u6570\uff0c\u4e0d\u4e00\u5b9a\u8981\u6709\uff0c\u636e\u60c5\u51b5\u800c\u5b9a\uff0c\u4f46\u662f\u4e00\u822c\u60c5\u51b5\u4e0b\u90fd\u4f1a\u6709\u5e76\u5728\u5185\u51fd\u6570\u4e2d\u4f7f\u7528\u5230<\/p>\n<p>\u6848\u4f8b<\/p>\n<div>\n<pre style=\"font-size: 1em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 1.2em 0px; line-height: 1.2em;\"><code style=\"font-size: 0.85em; overflow: auto; font-family: Consolas, Inconsolata, Courier, monospace; background: #292824; white-space: pre; overflow-x: auto; color: #a6a28c; margin: 0px 0.15em; display: block; border-radius: 3px; -moz-text-size-adjust: none; border: #cccccc 1px solid; padding: 0.5em;\">def func(x, y):\r\n    def line(z):\r\n        <span style=\"color: #b854d4;\">return<\/span> x * y - z\r\n    <span style=\"color: #b854d4;\">return<\/span> line\r\nline = func(<span style=\"color: #b65611;\">8<\/span>, <span style=\"color: #b65611;\">9<\/span>)\r\nprint(line(<span style=\"color: #b65611;\">10<\/span>))\r\n<\/code><\/pre>\n<\/div>\n<p>\u7ed3\u679c\u5f97\u5230 62<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-84\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-38-06.png\" alt=\"\" width=\"735\" height=\"90\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-38-06.png 735w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/02\/2020-02-20-21-38-06-300x37.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>\u5728\u8fd9\u4e2a\u6848\u4f8b\u4e2d\uff0c\u5916\u51fd\u6570func\u6709\u63a5\u6536\u53c2\u6570 x=8\uff0cy=9\uff0c\u5185\u51fd\u6570line\u63a5\u6536\u53c2\u6570z=10\uff0c\u5728\u5185\u51fd\u6570\u4f53\u4e2d\u8ba1\u7b97\u4e86a*x-b \u5373 8\u00d79-10\u7684\u503c\u4f5c\u4e3a\u8fd4\u56de\u503c\uff0c\u5916\u51fd\u6570\u8fd4\u56de\u5185\u51fd\u6570\u7684\u5f15\u7528\uff0c\u8fd9\u91cc\u7684\u5f15\u7528\u6307\u7684\u662f\u5185\u51fd\u6570line\u5728\u5185\u5b58\u4e2d\u7684\u8d77\u59cb\u5730\u5740\uff0c\u6700\u7ec8\u8c03\u7528\u5185\u51fd\u6570line()\u5f97\u5230\u8fd4\u56de\u503c62<\/p>\n<p><strong>\u95ed\u5305\u7684\u7528\u9014<\/strong><\/p>\n<p>Python\u4e2d\uff0c\u95ed\u5305\u7684\u4e3b\u8981\u7528\u9014\u5c31\u662f\u7528\u4e8e\u88c5\u9970\u5668\u7684\u5b9e\u73b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ed\u5305\u5e76\u4e0d\u53ea\u662f\u4e00\u4e2aPython\u4e2d\u7684\u6982\u5ff5\uff0c\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5e94\u7528\u8f83\u4e3a\u5e7f\u6cdb\u3002\u7406\u89e3Python\u4e2d\u7684\u95ed\u5305\u4e00\u65b9\u9762 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-python"],"aioseo_notices":[],"views":670,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":4,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/52\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}