{"id":57963,"date":"2025-08-15T23:29:56","date_gmt":"2025-08-15T15:29:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/57963.html"},"modified":"2025-08-15T23:29:56","modified_gmt":"2025-08-15T15:29:56","slug":"%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3-python-%e9%97%ad%e5%8c%85%ef%bc%9a%e4%bb%8e%e5%8e%9f%e7%90%86%e5%88%b0%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/57963.html","title":{"rendered":"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E9%97%AD%E5%8C%85%EF%BC%9F-toc\" style=\"margin-left:0px\">\u4e00\u3001\u4ec0\u4e48\u662f\u95ed\u5305&#xff1f;<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E6%9E%84%E6%88%90%E6%9D%A1%E4%BB%B6%EF%BC%88%E4%B8%89%E6%AD%A5%E8%B5%B0%EF%BC%89-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u95ed\u5305\u7684\u6784\u6210\u6761\u4ef6&#xff08;\u4e09\u6b65\u8d70&#xff09;<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E6%A0%B8%E5%BF%83%E4%BD%9C%E7%94%A8%EF%BC%9A%E7%95%99%E4%BD%8F%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F-toc\" style=\"margin-left:0px\">\u4e09\u3001\u95ed\u5305\u7684\u6838\u5fc3\u4f5c\u7528&#xff1a;\u7559\u4f4f\u5c40\u90e8\u53d8\u91cf<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E9%97%AD%E5%8C%85%E5%86%85%E9%83%A8%E4%BF%AE%E6%94%B9%E5%A4%96%E9%83%A8%E5%8F%98%E9%87%8F%EF%BC%9Anonlocal%20%E5%85%B3%E9%94%AE%E5%AD%97-toc\" style=\"margin-left:0px\">\u56db\u3001\u95ed\u5305\u5185\u90e8\u4fee\u6539\u5916\u90e8\u53d8\u91cf&#xff1a;nonlocal \u5173\u952e\u5b57<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E4%BD%BF%E7%94%A8%E9%97%AD%E5%8C%85%E7%9A%84%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9-toc\" style=\"margin-left:0px\">\u4e94\u3001\u4f7f\u7528\u95ed\u5305\u7684\u6ce8\u610f\u4e8b\u9879<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF-toc\" style=\"margin-left:0px\">\u516d\u3001\u95ed\u5305\u7684\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/p>\n<p id=\"%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u603b\u7ed3<\/p>\n<hr id=\"hr-toc\" \/>\n<p>\u5728 Python \u4e2d&#xff0c;\u95ed\u5305\u662f\u4e00\u4e2a\u770b\u4f3c\u62bd\u8c61\u5374\u975e\u5e38\u5b9e\u7528\u7684\u6982\u5ff5\u3002\u5b83\u80fd\u5e2e\u52a9\u6211\u4eec\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d \u201c\u7559\u4f4f\u201d \u5c40\u90e8\u53d8\u91cf&#xff0c;\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u4ee3\u7801\u5c01\u88c5\u3002\u672c\u6587\u5c06\u4ece\u95ed\u5305\u7684\u5b9a\u4e49\u3001\u6784\u6210\u6761\u4ef6\u3001\u4f5c\u7528\u5230\u5b9e\u9645\u5e94\u7528&#xff0c;\u5e26\u4f60\u5168\u9762\u638c\u63e1\u8fd9\u4e00\u7279\u6027\u3002<\/p>\n<h2 id=\"%E4%B8%80%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AF%E9%97%AD%E5%8C%85%EF%BC%9F\">\u4e00\u3001\u4ec0\u4e48\u662f\u95ed\u5305&#xff1f;<\/h2>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5d4c\u5957\u51fd\u6570\u7ed3\u6784&#xff1a;\u5728\u51fd\u6570\u5d4c\u5957\u7684\u524d\u63d0\u4e0b&#xff0c;\u5185\u90e8\u51fd\u6570\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf&#xff0c;\u5e76\u4e14\u5916\u90e8\u51fd\u6570\u8fd4\u56de\u4e86\u8fd9\u4e2a\u5185\u90e8\u51fd\u6570\u3002\u8fd9\u79cd\u7ed3\u6784\u80fd\u8ba9\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u4e0d\u88ab\u9500\u6bc1&#xff0c;\u4ece\u800c\u88ab\u5168\u5c40\u4f5c\u7528\u57df\u95f4\u63a5\u8bbf\u95ee\u3002<\/p>\n<p>\u4e3e\u4e2a\u76f4\u89c2\u7684\u4f8b\u5b50&#xff1a;<\/p>\n<p>def outer():<br \/>\n    num &#061; 20  # \u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf<br \/>\n    def inner():<br \/>\n        print(num)  # \u5185\u90e8\u51fd\u6570\u5f15\u7528\u5916\u90e8\u53d8\u91cf<br \/>\n    return inner  # \u5916\u90e8\u51fd\u6570\u8fd4\u56de\u5185\u90e8\u51fd\u6570<\/p>\n<p># \u8c03\u7528\u5916\u90e8\u51fd\u6570&#xff0c;\u5f97\u5230\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528<br \/>\nf &#061; outer()<br \/>\nf()  # \u8f93\u51fa20&#xff0c;\u6210\u529f\u8bbf\u95ee\u5230outer\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfnum<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d&#xff0c;inner\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u95ed\u5305&#xff0c;\u5b83 \u201c\u8bb0\u4f4f\u201d \u4e86outer\u51fd\u6570\u4e2d\u7684num\u53d8\u91cf&#xff0c;\u5373\u4fbfouter\u6267\u884c\u5b8c\u6bd5&#xff0c;num\u4e5f\u6ca1\u6709\u88ab\u56de\u6536\u3002<\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E6%9E%84%E6%88%90%E6%9D%A1%E4%BB%B6%EF%BC%88%E4%B8%89%E6%AD%A5%E8%B5%B0%EF%BC%89\">\u4e8c\u3001\u95ed\u5305\u7684\u6784\u6210\u6761\u4ef6&#xff08;\u4e09\u6b65\u8d70&#xff09;<\/h2>\n<p>\u8981\u521b\u5efa\u4e00\u4e2a\u95ed\u5305&#xff0c;\u5fc5\u987b\u6ee1\u8db3\u4e09\u4e2a\u6761\u4ef6&#xff0c;\u7f3a\u4e00\u4e0d\u53ef&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;\u6709\u5d4c\u5957&#xff1a;\u5b58\u5728\u51fd\u6570\u5d4c\u5957\u7ed3\u6784&#xff0c;\u5373\u4e00\u4e2a\u51fd\u6570&#xff08;\u5185\u90e8\u51fd\u6570&#xff09;\u5b9a\u4e49\u5728\u53e6\u4e00\u4e2a\u51fd\u6570&#xff08;\u5916\u90e8\u51fd\u6570&#xff09;\u5185\u90e8&#xff1b;<\/p>\n<p>&#xff08;2&#xff09;\u6709\u5f15\u7528&#xff1a;\u5185\u90e8\u51fd\u6570\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u4e2d\u5b9a\u4e49\u7684\u5c40\u90e8\u53d8\u91cf&#xff1b;<\/p>\n<p>&#xff08;3&#xff09;\u6709\u8fd4\u56de&#xff1a;\u5916\u90e8\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u5185\u90e8\u51fd\u6570\u672c\u8eab&#xff08;\u5373\u8fd4\u56de\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528&#xff09;\u3002<\/p>\n<p>\u8fd9\u4e09\u4e2a\u6761\u4ef6\u4e5f\u88ab\u79f0\u4e3a \u201c\u95ed\u5305\u4e09\u6b65\u8d70\u201d&#xff0c;\u7f3a\u5c11\u4efb\u4f55\u4e00\u6b65\u90fd\u65e0\u6cd5\u6784\u6210\u95ed\u5305\u3002\u6bd4\u5982&#xff0c;\u5982\u679c\u5916\u90e8\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u5185\u90e8\u51fd\u6570&#xff0c;\u6216\u8005\u5185\u90e8\u51fd\u6570\u6ca1\u6709\u5f15\u7528\u5916\u90e8\u53d8\u91cf&#xff0c;\u90fd\u4e0d\u7b97\u95ed\u5305\u3002<\/p>\n<h2 id=\"%E4%B8%89%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E6%A0%B8%E5%BF%83%E4%BD%9C%E7%94%A8%EF%BC%9A%E7%95%99%E4%BD%8F%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F\">\u4e09\u3001\u95ed\u5305\u7684\u6838\u5fc3\u4f5c\u7528&#xff1a;\u7559\u4f4f\u5c40\u90e8\u53d8\u91cf<\/h2>\n<p>\u5728 Python \u4e2d&#xff0c;\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e&#xff0c;\u5176\u5185\u90e8\u7684\u5c40\u90e8\u53d8\u91cf\u4f1a\u88ab \u201c\u5783\u573e\u56de\u6536\u673a\u5236\u201d \u56de\u6536&#xff0c;\u91ca\u653e\u5185\u5b58\u3002\u4f46\u95ed\u5305\u6253\u7834\u4e86\u8fd9\u4e00\u5e38\u89c4 \u2014\u2014 \u5b83\u80fd\u8ba9\u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u4ecd\u7136\u4fdd\u7559&#xff0c;\u4f9b\u5185\u90e8\u51fd\u6570\u540e\u7eed\u4f7f\u7528\u3002<\/p>\n<p>\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u95f4\u63a5\u8bbf\u95ee\u8fd9\u4e9b \u201c\u672c\u5e94\u88ab\u56de\u6536\u201d \u7684\u5c40\u90e8\u53d8\u91cf\u3002\u4f8b\u5982&#xff0c;\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u7d2f\u52a0\u5668&#xff1a;<\/p>\n<p>def counter():<br \/>\n    total &#061; 0  # \u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf<br \/>\n    def add(num):<br \/>\n        nonlocal total  # \u58f0\u660e\u5f15\u7528\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf<br \/>\n        total &#043;&#061; num<br \/>\n        print(total)<br \/>\n    return add<\/p>\n<p># \u521b\u5efa\u7d2f\u52a0\u5668<br \/>\ncount &#061; counter()<br \/>\ncount(1)  # \u8f93\u51fa1<br \/>\ncount(2)  # \u8f93\u51fa3&#xff08;1&#043;2&#xff09;<br \/>\ncount(3)  # \u8f93\u51fa6&#xff08;3&#043;3&#xff09;<\/p>\n<p>\u8fd9\u91cc\u7684total\u53d8\u91cf\u672c\u5e94\u5728counter\u6267\u884c\u540e\u88ab\u56de\u6536&#xff0c;\u4f46\u95ed\u5305\u8ba9\u5b83\u4e00\u76f4 \u201c\u5b58\u6d3b\u201d&#xff0c;\u4ece\u800c\u5b9e\u73b0\u4e86\u7d2f\u52a0\u529f\u80fd\u3002<\/p>\n<h2 id=\"%E5%9B%9B%E3%80%81%E9%97%AD%E5%8C%85%E5%86%85%E9%83%A8%E4%BF%AE%E6%94%B9%E5%A4%96%E9%83%A8%E5%8F%98%E9%87%8F%EF%BC%9Anonlocal%20%E5%85%B3%E9%94%AE%E5%AD%97\">\u56db\u3001\u95ed\u5305\u5185\u90e8\u4fee\u6539\u5916\u90e8\u53d8\u91cf&#xff1a;nonlocal \u5173\u952e\u5b57<\/h2>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u5185\u90e8\u51fd\u6570\u53ea\u80fd\u8bbf\u95ee\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u4fee\u6539\u3002\u5982\u679c\u5c1d\u8bd5\u4fee\u6539&#xff0c;Python \u4f1a\u5c06\u5176\u89c6\u4e3a\u5185\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u800c\u975e\u5916\u90e8\u53d8\u91cf\u3002<\/p>\n<p>\u8fd9\u65f6\u9700\u8981\u7528nonlocal\u5173\u952e\u5b57\u58f0\u660e\u53d8\u91cf \u2014\u2014 \u5b83\u544a\u8bc9 Python&#xff1a;\u201c\u8fd9\u4e2a\u53d8\u91cf\u4e0d\u662f\u5185\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u4e5f\u4e0d\u662f\u5168\u5c40\u53d8\u91cf&#xff0c;\u800c\u662f\u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u201d\u3002<\/p>\n<p>\u5bf9\u6bd4\u4e24\u4e2a\u573a\u666f&#xff1a;<\/p>\n<p># \u573a\u666f1&#xff1a;\u4e0d\u4f7f\u7528nonlocal&#xff08;\u4fee\u6539\u5931\u8d25&#xff09;<br \/>\ndef outer():<br \/>\n    count &#061; 0<br \/>\n    def inner():<br \/>\n        count &#061; 10  # \u88ab\u89c6\u4e3ainner\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u4e0d\u5f71\u54cdouter\u7684count<br \/>\n        print(&#034;\u5185\u90e8\u4fee\u6539\u540e&#xff1a;&#034;, count)  # \u8f93\u51fa10<br \/>\n    inner()<br \/>\n    print(&#034;\u5916\u90e8\u67e5\u770b&#xff1a;&#034;, count)  # \u8f93\u51fa0&#xff08;\u672a\u88ab\u4fee\u6539&#xff09;<br \/>\n    return inner<\/p>\n<p># \u573a\u666f2&#xff1a;\u4f7f\u7528nonlocal&#xff08;\u4fee\u6539\u6210\u529f&#xff09;<br \/>\ndef outer():<br \/>\n    count &#061; 0<br \/>\n    def inner():<br \/>\n        nonlocal count  # \u58f0\u660e\u5f15\u7528outer\u7684count<br \/>\n        count &#061; 10<br \/>\n        print(&#034;\u5185\u90e8\u4fee\u6539\u540e&#xff1a;&#034;, count)  # \u8f93\u51fa10<br \/>\n    inner()<br \/>\n    print(&#034;\u5916\u90e8\u67e5\u770b&#xff1a;&#034;, count)  # \u8f93\u51fa10&#xff08;\u6210\u529f\u4fee\u6539&#xff09;<br \/>\n    return inner<\/p>\n<p>\u53ef\u89c1&#xff0c;nonlocal\u662f\u95ed\u5305\u4e2d\u4fee\u6539\u5916\u90e8\u53d8\u91cf\u7684\u5173\u952e\u3002<\/p>\n<h2 id=\"%E4%BA%94%E3%80%81%E4%BD%BF%E7%94%A8%E9%97%AD%E5%8C%85%E7%9A%84%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9\">\u4e94\u3001\u4f7f\u7528\u95ed\u5305\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<p>\u867d\u7136\u95ed\u5305\u5f88\u7075\u6d3b&#xff0c;\u4f46\u4e5f\u6709\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9&#xff1a;\u7531\u4e8e\u95ed\u5305\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf&#xff0c;\u8fd9\u4e9b\u53d8\u91cf\u4f1a\u4e00\u76f4\u5360\u7528\u5185\u5b58&#xff0c;\u65e0\u6cd5\u88ab\u53ca\u65f6\u91ca\u653e&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6d88\u8017\u589e\u52a0\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5728\u4f7f\u7528\u95ed\u5305\u65f6&#xff0c;\u8981\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u53d8\u91cf\u5f15\u7528&#xff0c;\u786e\u4fdd\u53ea\u4fdd\u7559\u6838\u5fc3\u53d8\u91cf&#xff0c;\u9632\u6b62\u5185\u5b58\u6d6a\u8d39\u3002<\/p>\n<h2 id=\"%E5%85%AD%E3%80%81%E9%97%AD%E5%8C%85%E7%9A%84%E5%AE%9E%E9%99%85%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF\">\u516d\u3001\u95ed\u5305\u7684\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h2>\n<p>\u95ed\u5305\u7684\u7279\u6027\u8ba9\u5b83\u5728\u5f88\u591a\u573a\u666f\u4e2d\u5927\u653e\u5f02\u5f69&#xff1a;<\/p>\n<p>&#xff08;1&#xff09;\u6570\u636e\u5c01\u88c5&#xff1a;\u50cf\u524d\u9762\u7684\u7d2f\u52a0\u5668\u6848\u4f8b&#xff0c;\u7528\u95ed\u5305\u5c01\u88c5\u4e00\u4e2a \u201c\u79c1\u6709\u53d8\u91cf\u201d&#xff0c;\u53ea\u901a\u8fc7\u5185\u90e8\u51fd\u6570\u4fee\u6539\u548c\u8bbf\u95ee&#xff0c;\u907f\u514d\u5168\u5c40\u53d8\u91cf\u7684\u6ee5\u7528&#xff1b;<\/p>\n<p>&#xff08;2&#xff09;\u5ef6\u8fdf\u8ba1\u7b97&#xff1a;\u5728\u9700\u8981\u5ef6\u8fdf\u6267\u884c\u67d0\u6bb5\u903b\u8f91\u65f6&#xff0c;\u7528\u95ed\u5305\u4fdd\u5b58\u8ba1\u7b97\u6240\u9700\u7684\u53c2\u6570&#xff0c;\u540e\u7eed\u8c03\u7528\u65f6\u518d\u6267\u884c&#xff1b;<\/p>\n<p>&#xff08;3&#xff09;\u88c5\u9970\u5668\u57fa\u7840&#xff1a;\u88c5\u9970\u5668\u7684\u672c\u8d28\u5c31\u662f\u95ed\u5305&#xff0c;\u5b83\u901a\u8fc7\u95ed\u5305\u7279\u6027\u5728\u4e0d\u4fee\u6539\u539f\u51fd\u6570\u7684\u524d\u63d0\u4e0b&#xff0c;\u4e3a\u51fd\u6570\u6dfb\u52a0\u989d\u5916\u529f\u80fd\u3002<\/p>\n<h2 id=\"%E6%80%BB%E7%BB%93\">\u603b\u7ed3<\/h2>\n<p>\u95ed\u5305\u662f Python \u4e2d\u4e00\u79cd\u5f3a\u5927\u7684\u51fd\u6570\u7279\u6027&#xff0c;\u5b83\u901a\u8fc7 \u201c\u51fd\u6570\u5d4c\u5957 &#043; \u53d8\u91cf\u5f15\u7528 &#043; \u8fd4\u56de\u5185\u90e8\u51fd\u6570\u201d \u7684\u7ed3\u6784&#xff0c;\u5b9e\u73b0\u4e86\u5c40\u90e8\u53d8\u91cf\u7684\u6301\u4e45\u5316\u3002\u7406\u89e3\u95ed\u5305\u7684\u6784\u6210\u6761\u4ef6\u3001\u4fee\u6539\u5916\u90e8\u53d8\u91cf\u7684\u65b9\u6cd5\u53ca\u6ce8\u610f\u4e8b\u9879&#xff0c;\u80fd\u5e2e\u52a9\u6211\u4eec\u5199\u51fa\u66f4\u7075\u6d3b\u3001\u66f4\u4f18\u96c5\u7684\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb240\u6b21\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5d4c\u5957\u51fd\u6570\u7ed3\u6784\uff1a\u5728\u51fd\u6570\u5d4c\u5957\u7684\u524d\u63d0\u4e0b\uff0c\u5185\u90e8\u51fd\u6570\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u5e76\u4e14\u5916\u90e8\u51fd\u6570\u8fd4\u56de\u4e86\u8fd9\u4e2a\u5185\u90e8\u51fd\u6570\u3002\u8fd9\u79cd\u7ed3\u6784\u80fd\u8ba9\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u4e0d\u88ab\u9500\u6bc1\uff0c\u4ece\u800c\u88ab\u5168\u5c40\u4f5c\u7528\u57df\u95f4\u63a5\u8bbf\u95ee\u3002num = 20 # \u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfprint(num) # \u5185\u90e8\u51fd\u6570\u5f15\u7528\u5916\u90e8\u53d8\u91cfreturn inner # \u5916\u90e8\u51fd\u6570\u8fd4\u56de\u5185\u90e8\u51fd\u6570# \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff0c\u5f97\u5230\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528f() # \u8f93\u51fa20\uff0c\u6210\u529f\u8bbf\u95ee\u5230outer\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfnum\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cinner\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u95ed\u5305\uff0c\u5b83 \u201c\u8bb0\u4f4f\u201d \u4e86outer\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190],"topic":[],"class_list":["post-57963","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/57963.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb240\u6b21\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5d4c\u5957\u51fd\u6570\u7ed3\u6784\uff1a\u5728\u51fd\u6570\u5d4c\u5957\u7684\u524d\u63d0\u4e0b\uff0c\u5185\u90e8\u51fd\u6570\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u5e76\u4e14\u5916\u90e8\u51fd\u6570\u8fd4\u56de\u4e86\u8fd9\u4e2a\u5185\u90e8\u51fd\u6570\u3002\u8fd9\u79cd\u7ed3\u6784\u80fd\u8ba9\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u4e0d\u88ab\u9500\u6bc1\uff0c\u4ece\u800c\u88ab\u5168\u5c40\u4f5c\u7528\u57df\u95f4\u63a5\u8bbf\u95ee\u3002num = 20 # \u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfprint(num) # \u5185\u90e8\u51fd\u6570\u5f15\u7528\u5916\u90e8\u53d8\u91cfreturn inner # \u5916\u90e8\u51fd\u6570\u8fd4\u56de\u5185\u90e8\u51fd\u6570# \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff0c\u5f97\u5230\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528f() # \u8f93\u51fa20\uff0c\u6210\u529f\u8bbf\u95ee\u5230outer\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfnum\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cinner\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u95ed\u5305\uff0c\u5b83 \u201c\u8bb0\u4f4f\u201d \u4e86outer\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/57963.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-15T15:29:56+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57963.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/57963.html\",\"name\":\"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-15T15:29:56+00:00\",\"dateModified\":\"2025-08-15T15:29:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/57963.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/57963.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57963.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/57963.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb240\u6b21\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5d4c\u5957\u51fd\u6570\u7ed3\u6784\uff1a\u5728\u51fd\u6570\u5d4c\u5957\u7684\u524d\u63d0\u4e0b\uff0c\u5185\u90e8\u51fd\u6570\u5f15\u7528\u4e86\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u5e76\u4e14\u5916\u90e8\u51fd\u6570\u8fd4\u56de\u4e86\u8fd9\u4e2a\u5185\u90e8\u51fd\u6570\u3002\u8fd9\u79cd\u7ed3\u6784\u80fd\u8ba9\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u4e0d\u88ab\u9500\u6bc1\uff0c\u4ece\u800c\u88ab\u5168\u5c40\u4f5c\u7528\u57df\u95f4\u63a5\u8bbf\u95ee\u3002num = 20 # \u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfprint(num) # \u5185\u90e8\u51fd\u6570\u5f15\u7528\u5916\u90e8\u53d8\u91cfreturn inner # \u5916\u90e8\u51fd\u6570\u8fd4\u56de\u5185\u90e8\u51fd\u6570# \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff0c\u5f97\u5230\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528f() # \u8f93\u51fa20\uff0c\u6210\u529f\u8bbf\u95ee\u5230outer\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cfnum\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cinner\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u95ed\u5305\uff0c\u5b83 \u201c\u8bb0\u4f4f\u201d \u4e86outer\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/57963.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-15T15:29:56+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/57963.html","url":"https:\/\/www.wsisp.com\/helps\/57963.html","name":"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-15T15:29:56+00:00","dateModified":"2025-08-15T15:29:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/57963.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/57963.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/57963.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6df1\u5165\u7406\u89e3 Python \u95ed\u5305\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u8df5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=57963"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57963\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=57963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=57963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=57963"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=57963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}