{"id":599,"date":"2018-06-10T15:52:57","date_gmt":"2018-06-10T07:52:57","guid":{"rendered":"http:\/\/zkeeer.space\/?p=599"},"modified":"2018-10-31T17:33:06","modified_gmt":"2018-10-31T09:33:06","slug":"%e6%b5%85%e6%b7%a1python3%e7%9a%84%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86%e5%92%8c%e5%bc%95%e7%94%a8","status":"publish","type":"post","link":"http:\/\/zkeeer.space\/?p=599","title":{"rendered":"\u6d45\u6de1python3\u7684\u5185\u5b58\u7ba1\u7406\u548c\u5f15\u7528"},"content":{"rendered":"<p>\u5148\u7531\u4e00\u4e2a\u4f8b\u5b50\u5f15\u51fa\u4e3b\u9898\uff1a\u6700\u8fd1\u5de5\u4f5c\u4e2d\u9047\u5230\u4e00\u4e2abug\uff0c\u767e\u601d\u4e0d\u5f97\u5176\u89e3\uff0c\u660e\u660e\u903b\u8f91\u4e5f\u901a\uff0ctry\/except\u4e5f\u6ca1\u62a5\u9519\uff0c\u4e3a\u4ec0\u4e48\u8fd0\u884c\u7ed3\u679c\u5374\u4e0d\u662f\u6211\u60f3\u8981\u7684\uff1f\u4e0d\u6025\u7740\u770b\u7ed3\u679c\u7684\u8bdd\uff0c\u4e00\u8d77\u731c\u4e00\u4e0b\u3002<\/p>\n<p>\u5927\u4f53\u662f\u8fd9\u6837\u7684\uff0c\u6211\u5b9a\u4e49\u4e86\u4e00\u4e2a\u516c\u53f8\u7c7b\uff1aCompany<\/p>\n<pre>class Company:\r\n    def __init__(self):\r\n        self.company_name = \"\"\r\n        self.location = \"\"\r\n        self.phone = \"\"\r\n        self.employee = \"\"\r\n    def __str__(self):\r\n        return \"company:{}\\tlocation:{}\\tphone:{}\\tname:{}\".format(self.company_name,self.location,self.phone,self.employee)<\/pre>\n<p>\u6bcf\u4e2a\u516c\u53f8\u6709\u591a\u4e2a\u5458\u5de5\uff0c\u6211\u624b\u4e0a\u6709\u4e00\u4e32\u4eba\u5458\u540d\u5355\uff0c\u5c31\u60f3\u7740\u6bcf\u4e2a\u5458\u5de5\uff08\u5305\u542b\u516c\u53f8\u4fe1\u606f\uff09\u5f53\u4f5c\u4e00\u6761\u5199\u5165\u6570\u636e\u5e93\u91cc\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u6211\u4ee3\u7801\u662f\u8fd9\u6837\u5199\u7684\u3002<\/p>\n<pre>def get_employee_list(company, location, phone, employee_list):\r\n    return_employee_list = list()\r\n    company_cls = Company()\r\n    company_cls.company_name = company\r\n    company_cls.location = location\r\n    company_cls.phone = phone\r\n    for employee_item in employee_list:\r\n        company_cls.employee = employee_item\r\n        return_employee_list.append(company_cls)\r\n    return return_employee_list<\/pre>\n<p>\u6211\u5c31\u60f3\u7740\u7528\u65b0\u7684employee\u53bb\u8986\u76d6\u65e7\u7684employee\uff0c\u7136\u540e\u76f4\u63a5\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\u3002\u4ee3\u7801\u7b80\u6d01\uff0c\u5f88\u7701\u4e8b\uff0c\u903b\u8f91\u4e5f\u6ca1\u9519\uff0c\u4f46\u5c31\u662f\u51fa\u9519\u4e86\u3002<\/p>\n<p>\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n<pre>e_list = ['\u5f20\u4e09', '\u674e\u56db', '\u738b\u4e8c\u9ebb\u5b50']\r\nfor item in get_employee_list(\"Github\",\"USA\",\"Don't know\" ,e_list):\r\n    print(item.__str__())\r\n\r\n\r\ncompany:Github location:USA phone:Don't know name:\u738b\u4e8c\u9ebb\u5b50\r\ncompany:Github location:USA phone:Don't know name:\u738b\u4e8c\u9ebb\u5b50\r\ncompany:Github location:USA phone:Don't know name:\u738b\u4e8c\u9ebb\u5b50<\/pre>\n<p>\u662f\u4e0d\u662f\u5f88\u610f\u5916\uff1f<\/p>\n<p>\u6211\u8981\u662f\u8fd9\u6837\u8f93\u51fa\uff0c\u4f60\u5c31\u660e\u767d\u4e86\uff08\u524d\u63d0\u662f\u4e0d\u91cd\u8f7d__str__()\uff09\u3002<\/p>\n<pre>e_list = ['\u5f20\u4e09', '\u674e\u56db', '\u738b\u4e8c\u9ebb\u5b50']\r\nfor item in get_employee_list(\"Github\", \"USA\", \"Don't know\", e_list):\r\n    print(item)\r\n\r\n&lt;__main__.Company object at 0x000002974444B198&gt;\r\n&lt;__main__.Company object at 0x000002974444B198&gt;\r\n&lt;__main__.Company object at 0x000002974444B198&gt;<\/pre>\n<p>\u660e\u767d\u4e86\u5427\uff0c\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\uff01<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f7f\u7528append\u5f80\u5217\u8868\u4e2d\u6dfb\u52a0\u7684\u90fd\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u4e2a\u72ec\u7acb\u65e0\u5173\u7684\u5bf9\u8c61\u3002\u6240\u4ee5\u8bf4\uff0c\u6211\u662f\u5f80\u5217\u8868\u4e2d\u6dfb\u52a0\u4e86\u540c\u4e00\u5bf9\u8c61\u7684\u4e09\u4e2a\u5f15\u7528\u3002\u9519\u7528C\u8bed\u8a00\u7684\u601d\u8def\u5199\u4e86python\u3002<\/p>\n<p>\u4e0b\u9762\u5148\u628a\u7a0b\u5e8f\u6539\u8fc7\u6765\uff1a<\/p>\n<pre>def get_employee_list(company, location, phone, employee_list):\r\n    return_employee_list = list()\r\n    for employee_item in employee_list:\r\n        company_cls = Company()\r\n        company_cls.company_name = company\r\n        company_cls.location = location\r\n        company_cls.phone = phone\r\n        company_cls.employee = employee_item\r\n        return_employee_list.append(company_cls)\r\n    return return_employee_list\r\n\r\n\r\ncompany:Github location:USA phone:Don't know name:\u5f20\u4e09\r\ncompany:Github location:USA phone:Don't know name:\u674e\u56db\r\ncompany:Github location:USA phone:Don't know name:\u738b\u4e8c\u9ebb\u5b50<\/pre>\n<p>\u501f\u7740\u4e0a\u9762\uff0c\u8bf4\u8bf4python3\u7684\u5bf9\u8c61\u548c\u5f15\u7528\uff0c\u5185\u5b58\u7ba1\u7406\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u9996\u5148\uff0c\u4ec1\u6148\u7684\u72ec\u88c1\u8005\u544a\u8bc9\u4e16\u4eba\uff0c\u5728python\u4e2d\u4e07\u7269\u7686\u5bf9\u8c61\u3002<\/p>\n<h4>\u5f15\u7528\u8ba1\u6570<\/h4>\n<p>python\u4e2d\u53d8\u91cf\uff0c\u5e94\u5f53\u770b\u4f5c\u662f\u5bf9\u8c61\u7684\u4e00\u4e2a\u6807\u8bc6\uff0c\u6216\u8005\u662f\u5bf9\u8c61\u7684\u4e00\u4e2a\u5f15\u7528\u3002\u5f53\u6211\u4eec\u50cf\u4e0b\u9762\u4e00\u6837\u8d4b\u503c\u65f6\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0\uff0cpython\u628a\u53d8\u91cfb\u5f53\u4f5c\u662ftest\u7684\u4e00\u4e2a\u5f15\u7528\u5904\u7406\uff0c\u4e5f\u53ef\u4ee5\u53eb\u505a\u6d45\u62f7\u8d1d\uff08\u540e\u9762\u4f1a\u8bf4\u62f7\u8d1d\u76f8\u5173\uff09\u3002<\/p>\n<pre>from sys import getrefcount\r\n\r\na = 'test'\r\nprint(getrefcount('test')) #\u67e5\u770b 'test'\u5f15\u7528\u8ba1\u6570\r\nb = a\r\nprint(getrefcount('test'))\r\n\r\nprint(id(a), id(b), a is b) #\u67e5\u770ba b\u7684\u5185\u5b58\u5730\u5740\r\n\r\nc = 'test1'\r\nd = 'test1'\r\n\r\nprint(id(c), id(d), c is d)\r\n\r\n#\u8fd0\u884c\u7ed3\u679c\r\n4\r\n5\r\n2150002613360 2150002613360 True\r\n2150008644696 2150008644696 True<\/pre>\n<p>tips: is\u548c==\u4e0d\u80fd\u901a\u7528\uff0cis\u6bd4\u8f83\u7684\u662f\u5185\u5b58\u5730\u5740\uff0c\u770b\u4e24\u4e2a\u53d8\u91cf\u662f\u4e0d\u662f\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff1b==\u662f\u6bd4\u8f83\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\uff0c\u770b\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-601 size-medium\" src=\"http:\/\/zkeeer.space\/wp-content\/uploads\/2018\/06\/\u5f15\u7528-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"http:\/\/zkeeer.space\/wp-content\/uploads\/2018\/06\/\u5f15\u7528-300x169.png 300w, http:\/\/zkeeer.space\/wp-content\/uploads\/2018\/06\/\u5f15\u7528-768x432.png 768w, http:\/\/zkeeer.space\/wp-content\/uploads\/2018\/06\/\u5f15\u7528.png 960w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>\u8fd9\u5c31\u662fab\u53d8\u91cf\u548c&#8217;test&#8217;\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u770b\u5230\u8fd9\u91cc\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff0c\u90a3\u6211\u4fee\u6539a\uff0c\u53d8\u91cfb\u662f\u4e0d\u662f\u4e5f\u4f1a\u8ddf\u7740\u53d8\u5316\uff1f\u7b54\u6848\u662f\u4e0d\u4f1a\uff0c\u4fee\u6539a\u7684\u65f6\u5019\uff0c\u4f1a\u91cd\u65b0\u751f\u6210\u4e00\u4e2a\u5bf9\u8c61\u8d4b\u7ed9a\u3002\u8fd9\u5c31\u662f<strong>\u5f15\u7528\u8ba1\u6570\u3002<\/strong><\/p>\n<p>\u8fd9\u70b9\u8ddfC\u8bed\u8a00\u4e0d\u540c\uff0cC\u4f1a\u4e3a\u6bcf\u4e2a\u53d8\u91cf\u90fd\u7533\u8bf7\u4e00\u4e2a\u7a7a\u95f4\uff0c\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48a\u548cb\u7684\u6307\u9488\u4e0d\u4e00\u81f4\u7684\u539f\u56e0\uff08\u5047\u8bbe\u4e0a\u9762abcd\u53d8\u91cf\u5728C\u8bed\u8a00\u4e2d\uff09\u3002\u5f53\u7136\uff0cpython3\u4e2d\u7684\u53d8\u91cf\u4f60\u4e5f\u53ef\u4ee5\u770b\u4f5cC\u8bed\u8a00\u4e2d\u7684\u6307\u9488\u3002<\/p>\n<p>\u5f53\u7136\u8fd8\u6709\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u4f1a\u5bfc\u81f4<strong>\u5f15\u7528\u8ba1\u6570\u589e\u52a0<\/strong>\uff1a<\/p>\n<p>1.<strong>\u4f20\u53c2foo(a)<\/strong>\uff1a \u8fd9\u4e5f\u662fpython\u552f\u4e00\u652f\u6301\u7684\u4f20\u53c2\u65b9\u5f0f\uff1a\u5171\u4eab\u4f20\u53c2\u3002\u5373\u5f62\u53c2\u4e3a\u5b9e\u53c2\u7684\u4e00\u4e2a\u526f\u672c\uff0c\u6216\u8005\u53eb\u5b9e\u53c2\u7684\u522b\u540d\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u5f15\u7528\uff09\uff0c\u8fd9\u6837\u7684\u4f20\u53c2\u7684\u95ee\u9898\u662f\uff0c\u53c2\u6570\u4e3a\u53ef\u53d8\u7c7b\u578b\u65f6\uff0c\u4fee\u6539\u5f62\u53c2\u4f1a\u5bfc\u81f4\u5b9e\u53c2\u53d1\u751f\u6539\u53d8\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>def foo(a):\r\n    a.append(10)\r\n\r\nb = [1, 2]\r\nprint(b)\r\nfoo(b)\r\nprint(b)\r\n\r\n#\u8fd0\u884c\u7ed3\u679c\r\n[1, 2]\r\n[1, 2, 10]<\/pre>\n<p>2.\u5c06\u53d8\u91cf\u4f5c\u4e3a\u5bb9\u5668\uff08list\u3001dict\u7b49\u7c7b\u578b\uff09\u7684\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<pre>a = 10\r\nmylist = [1, 2, a]<\/pre>\n<p>&nbsp;<\/p>\n<p>\u90a3\u4e48\u4ec0\u4e48\u60c5\u51b5\u4f1a\u5bfc\u81f4<strong>\u5f15\u7528\u8ba1\u6570\u51cf\u5c11<\/strong>\u5462\uff1f<\/p>\n<p>1.\u53d8\u91cf\u79bb\u5f00\u4f5c\u7528\u57df\u4e86\uff0c\u592d\u5bff\u5566\uff0c\u79bb\u5f00\u4f5c\u7528\u57df\u8fd8\u4e0d\u6b7b\u5c31\u6ca1\u5929\u7406\u4e86\u3002\u8fd9\u65f6\u5019\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u4f1a-1\uff0c\u4f46\u5bf9\u8c61\u4e0d\u4e00\u5b9a\u6b7b\uff08\u53ef\u601c\u4f60\u4eec\u8fde\u5bf9\u8c61\u90fd\u6ca1\u6709\uff0c\u6211\u5c31\u4e0d\u4e00\u6837\u4e86\uff0c\u554a\u54c8\u54c8\uff09\u3002<\/p>\n<p>2.\u5bf9\u8c61\u7684\u4e00\u4e2a\u522b\u540d\uff08\u4e5f\u5c31\u662f\u4e00\u4e2a\u5f15\u7528\uff09\u88ab\u663e\u793a\u5730\u9500\u6bc1\uff0cdel a\u3002<\/p>\n<p><strong>del\u53ea\u80fd\u5220\u9664\u5f15\u7528\uff0c\u5f15\u7528\u4e3a0\u65f6\u91ca\u653e\u5bf9\u8c61<\/strong><\/p>\n<p><strong>del\u53ea\u80fd\u5220\u9664\u5f15\u7528\uff0c\u5f15\u7528\u4e3a0\u65f6\u91ca\u653e\u5bf9\u8c61<\/strong><\/p>\n<p><strong>del\u53ea\u80fd\u5220\u9664\u5f15\u7528\uff0c\u5f15\u7528\u4e3a0\u65f6\u91ca\u653e\u5bf9\u8c61<\/strong><\/p>\n<p>\u4e0d\u8981\u518d\u542c\u4ec0\u4e48\u4ec0\u4e48\u4f7f\u7528del\u76f4\u63a5\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>3.\u8fd8\u8bb0\u5f97\u4e0a\u9762\u8bf4\u7684<em>\u53ef\u53d8\u5bf9\u8c61<\/em>\u7684\u4e00\u4e2a\u5f15\u7528\u88ab\u4fee\u6539\u65f6\uff0c\u4f1a\u5bfc\u81f4\u5176\u4ed6\u5f15\u7528\u4e5f\u53d1\u751f\u53d8\u5316\u3002\u8fd9\u91cc\u662f<em>\u4e0d\u53ef\u53d8\u7684\u5f15\u7528<\/em>\uff0c\u4e0d\u53ef\u53d8\u7684\u5bf9\u8c61\uff0c\u8fdb\u884c\u4fee\u6539\u65f6\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\u8d4b\u7ed9\u53d8\u91cf\uff0c\u6b64\u65f6\u539f\u5148\u5bf9\u8c61\u7684<del>\u5907\u80ce<\/del>\u5f15\u7528-1\u3002<\/p>\n<p>4.\u4e0a\u9762\u8bf4\u53d8\u91cf\u4f5c\u4e3a\u5bb9\u5668\u7684\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5f15\u7528\u8ba1\u6570+1\uff0c\u81ea\u7136\u2026\u2026\u65f6\uff0c\u5f15\u7528\u8ba1\u6570-1\u3002<\/p>\n<p>5.\u5f15\u7528\u8fd9\u4e2a\u53d8\u91cf\u7684\u5bf9\u8c61\u76f4\u63a5\u6ca1\u4e86\uff0c\u90a3\u8fd9\u4e2a\u53d8\u91cf\u6307\u5411\u7684\u5bf9\u8c61\u7684\u53d8\u91cf\u5c31\u5c11\u4e86\u4e00\u4e2a\uff0c\u8fd9\u4e2a\u53d8\u91cf\u6307\u5411\u7684\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570-1.\uff08\u5176\u5b9e\u8fd9\u53e5\u8bdd\u53ef\u4ee5\u7b80\u5355\u8bf4\uff0c\u6211\u504f\u4e0d\uff0c\u9634\u5929\u5fc3\u60c5\u4e0d\u597d\uff09<\/p>\n<p>&nbsp;<\/p>\n<p>\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u6709\u589e\u6709\u51cf\uff0c\u5f53\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u51cf\u5c11\u52300\u65f6\uff0c\u5df2\u7ecf\u6ca1\u6709\u4efb\u4f55\u5f15\u7528\u53ef\u4ee5\u6307\u5411\u8fd9\u4e2a\u5bf9\u8c61\u4e86\uff0c\u7528\u6237\u66f4\u4e0d\u80fd\u901a\u8fc7\u4efb\u4f55\u65b9\u5f0f\u63a5\u89e6\u5230\u8fd9\u4e2a\u5bf9\u8c61\u4e86\uff0c\u8fd9\u65f6\u5019\u5c31\u8be5\u8003\u8651\u4e0b<strong>\u5783\u573e\u56de\u6536<\/strong>\u4e86\u3002<\/p>\n<h4><strong>\u5783\u573e\u56de\u6536<\/strong><\/h4>\n<p>\u5f53\u7136python\u4e5f\u4e0d\u4f1a\u9891\u7e41\u7684\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u9891\u7e41\u7684\u5783\u573e\u56de\u6536\u4f1a\u5bfc\u81f4python\u5de5\u4f5c\u6548\u7387\u5927\u5927\u964d\u4f4e\uff1b\u90a3\u7b49\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u5728\u8fdb\u884c\u5783\u573e\u56de\u6536\uff0c\u5f88\u6709\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u3002\u6362\u4e2a\u4e2d\u548c\u7684\u65b9\u6cd5\uff0cpython\u4f1a\u8bb0\u5f55\u5206\u914d\u5bf9\u8c61\u548c\u53d6\u6d88\u5206\u914d\u5bf9\u8c61\u7684\u6b21\u6570\uff0c\u5f53\u4e24\u8005\u7684\u5dee\u503c\u5230\u8fbe\u67d0\u4e00\u9608\u503c\u65f6\uff0cpython\u4f1a\u542f\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528<\/p>\n<pre>import gc\r\ngc.collect()<\/pre>\n<p>\u624b\u52a8\u8fdb\u884c\u5783\u573e\u56de\u6536\uff08\u4e00\u822c\u6ca1\u6709\u5fc5\u8981\uff09\u3002<\/p>\n<p>\u8fbe\u5230\u9608\u503c\u65f6\uff0c\u6240\u6709\u5bf9\u8c61\u90fd\u4f1a\u88ab\u68c0\u6d4b\u548c\u56de\u6536\u5417\uff1f\u5f53\u7136\u4e0d\u662f\uff0cpython\u5783\u573e\u56de\u6536\u4f7f\u7528\u7684\u662f<strong>\u5206\u4ee3\u56de\u6536<\/strong>\uff0c\u8ddf\u9875\u9762\u7f6e\u6362\u7b97\u6cd5\u4e2d\u90a3\u4e2a\u6700\u5c11\u4f7f\u7528\u7b97\u6cd5\u7c7b\u4f3c\uff0c\u5bf9\u8c61\u5206\u4e3a1\uff0c2\uff0c3\u4ee3\uff08\u51c6\u786e\u7684\u8bf4\u5e94\u8be5\u662f0\uff0c1\uff0c2\uff09\uff0c\u521a\u5206\u914d\u7684\u5bf9\u8c61\u4e3a1\uff0c\u8fdb\u884c\u5783\u573e\u56de\u6536\u65f6\uff0c\u5bf9\u8c61\u5f15\u7528\u4e0d\u662f0\uff0c\u8fd8\u5728\u4f7f\u7528\u5219\u5bf9\u8c61\u7684\u4ee3\u6b21+1\uff0c\u540c\u65f6\u4f1a\u51cf\u5c11\u5bf9\u9ad8\u4ee3\u6b21\u5bf9\u8c61\u7684\u626b\u63cf\u3002<\/p>\n<p>\u5bf9\u4e8e<strong>\u5faa\u73af\u5f15\u7528<\/strong>\u7684\u95ee\u9898\uff0c\u5f53\u4f60\u7684\u4ee3\u7801\u662f\u4e0b\u9762\u8fd9\u6837\u7684\u65f6\u5019<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/zkeeer.space\/wp-content\/uploads\/2018\/06\/snakebiteitself-150x150.jpg\" \/><\/p>\n<p>\u4e0d\u597d\u610f\u601d\uff0c\u653e\u9519\u56fe\u4e86\u3002\u5e94\u8be5\u662f\u4e0b\u9762\u8fd9\u6837\u65f6\uff1a<\/p>\n<pre>a = [1,2]\r\nb = a\r\na.append(b)<\/pre>\n<p>b\u5f15\u7528a\uff0ca\u5f15\u7528b\uff0c\u5b50\u5b50\u5b59\u5b59\u65e0\u7a77\u532e\u4e5f\u3002\u5f15\u7528\u8ba1\u6570\u4e0d\u4e3a0\uff0c\u6c38\u8fdc\u5360\u5728\u5185\u5b58\u91cc\u3002<\/p>\n<p>python\u4f1a\u590d\u5236\u6bcf\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\uff0c\u5047\u8bbea\u7684\u5f15\u7528\u8ba1\u6570\u4e3aref_a\uff0cb\u7684\u5f15\u7528\u8ba1\u6570\u4e3aref_b\uff0cpython\u4f1a\u904d\u5386a\uff0c\u5c06a\u7684\u6240\u7528\u5f15\u7528\u5bf9\u8c61\uff08\u8fd9\u91cc\u53ea\u6709b\uff09\uff0c\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570-1\uff08\u8fd9\u91cc\u53ea\u7528ref_b &#8211; 1\uff09\u3002\u540c\u7406\u4e5f\u4f1a\u904d\u5386b\u3002\u5f53\u904d\u5386\u7ed3\u675f\u540e\uff0c\u5047\u8bbe\u67d0\u5bf9\u8c61ref_x\u4e0d\u4e3a0\uff0c\u90a3\u4e48x\u5f15\u7528\u7684\u5bf9\u8c61\uff0c\u4ee5\u53ca\u66f4\u4e0b\u6e38\u7684\u5bf9\u8c61\u4f1a\u88ab\u4fdd\u7559\uff0c\u5176\u4ed6ref\u4e3a0\u7684\u5bf9\u8c61\u4f1a\u88ab\u5220\u9664\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4e0a\u9762\u8bf4\u4e86\u5f88\u591a\u5bf9\u8c61\u554a\uff0c\u5f15\u7528\u554a\uff0c\u5220\u9664\u554a\uff0c\u91ca\u653e\u554a\u3002\u4f46\u662f\u91ca\u653e\u540e\u7684\u5185\u5b58\u5462\uff1f<\/p>\n<h4><strong>\u5185\u5b58\u6c60\u673a\u5236<\/strong><\/h4>\n<p>(\u80fd\u529b\u4e00\u822c\u6c34\u5e73\u6709\u9650\uff0c\u8fd9\u91cc\u5c11\u505a\u89e3\u91ca\uff0c\u9644\u4e0a\u4e00\u4e9b\u6750\u6599\u5927\u5bb6\u6709\u5174\u8da3\u7684\u53bb\u7814\u7a76\u4e0b)<\/p>\n<p>python\u5bf9\u4e8e\u5c0f\u4e8e512\u5b57\u8282\u7684\u5185\u5b58\uff0c\u4f1a\u81ea\u5df1\u7ba1\u7406\uff0c\u907f\u514d\u9891\u7e41\u8c03\u7528C\u7684malloc\/free\uff0c\u9020\u6210\u6548\u7387\u4f4e\u4e0b\u3002\u5bf9\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\uff08list\u3001str\u3001dict\u2026\u2026\uff09\uff0c\u90fd\u4f1a\u6709\u72ec\u7acb\u7684\u5185\u5b58\u6c60\u8fdb\u884c\u7ba1\u7406\uff0c\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u4e4b\u95f4\u4e0d\u5171\u4eab\u5185\u5b58\u6c60\u3002\u6bd4\u5982\u5f53\u4e00\u4e2a\u6574\u578b\u5bf9\u8c61\u88ab\u56de\u6536\u3001\u5185\u5b58\u91ca\u653e\uff0c\u8fd9\u5757\u5185\u5b58\u4f1a\u88ab\u653e\u5165\u6574\u578b\u7684\u5185\u5b58\u6c60\u4e2d\uff0c\u4e0d\u80fd\u7528\u4e8e\u6d6e\u70b9\u6570\u6216\u8005\u5217\u8868\uff0c\u4e0b\u6b21\u521b\u5efa\u65b0\u7684\u6574\u578b\u5bf9\u8c61\u65f6\uff0c\u518d\u4ece\u6574\u578b\u5bf9\u8c61\u7684\u5185\u5b58\u6c60\u4e2d\u5206\u914d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>python\u5185\u5b58\u7ba1\u7406\u76f8\u5173\u535a\u6587\uff1a<\/p>\n<p>https:\/\/www.cnblogs.com\/pinganzi\/p\/6646742.html#_labelTop<\/p>\n<blockquote data-secret=\"1eh75YMgpd\" class=\"wp-embedded-content\"><p><a href=\"http:\/\/python.jobbole.com\/83533\/\">Python\u6e90\u7801\u9605\u8bfb-\u5185\u5b58\u7ba1\u7406\u673a\u5236(\u4e00)<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/python.jobbole.com\/83533\/embed\/#?secret=1eh75YMgpd\" data-secret=\"1eh75YMgpd\" width=\"600\" height=\"338\" title=\"\u300aPython\u6e90\u7801\u9605\u8bfb-\u5185\u5b58\u7ba1\u7406\u673a\u5236(\u4e00)\u300b\u2014Python - \u4f2f\u4e50\u5728\u7ebf\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p>PS\uff1a\u5927\u5bb6\u60f3\u770b\u6211\u5199\u54ea\u65b9\u9762\u5185\u5bb9\uff0c\u53ef\u4ee5\u5728\u4e0b\u9762\u7559\u8a00\uff0c^_^\u8c22\u8c22\u652f\u6301~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u7531\u4e00\u4e2a\u4f8b\u5b50\u5f15\u51fa\u4e3b\u9898\uff1a\u6700\u8fd1\u5de5\u4f5c\u4e2d\u9047\u5230\u4e00\u4e2a &hellip; <a href=\"http:\/\/zkeeer.space\/?p=599\" class=\"more-link\">More <span class=\"screen-reader-text\">\u6d45\u6de1python3\u7684\u5185\u5b58\u7ba1\u7406\u548c\u5f15\u7528<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":602,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[11,56,54,55],"_links":{"self":[{"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/posts\/599"}],"collection":[{"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zkeeer.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=599"}],"version-history":[{"count":9,"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/posts\/599\/revisions"}],"predecessor-version":[{"id":625,"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/posts\/599\/revisions\/625"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/zkeeer.space\/index.php?rest_route=\/wp\/v2\/media\/602"}],"wp:attachment":[{"href":"http:\/\/zkeeer.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zkeeer.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zkeeer.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}