{"id":1183485,"date":"2025-01-15T19:15:09","date_gmt":"2025-01-15T11:15:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1183485.html"},"modified":"2025-01-15T19:15:12","modified_gmt":"2025-01-15T11:15:12","slug":"python%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%8f%96%e5%9d%80%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1183485.html","title":{"rendered":"python\u5982\u4f55\u4f7f\u7528\u53d6\u5740\u7b26"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25133233\/93070a23-11e4-4785-a670-a43f005fd94f.webp\" alt=\"python\u5982\u4f55\u4f7f\u7528\u53d6\u5740\u7b26\" \/><\/p>\n<p><p> Python\u4e2d\u7684\u53d6\u5740\u7b26\uff08address-of operator\uff09\u4e3b\u8981\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002\u5728Python\u4e2d\u5e76\u6ca1\u6709\u76f4\u63a5\u7684\u53d6\u5740\u7b26\uff0c\u5982C\u8bed\u8a00\u4e2d\u7684<code>&amp;<\/code>\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<code>id()<\/code>\u6765\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002<strong>\u4f7f\u7528id()\u51fd\u6570\u3001\u4f7f\u7528ctypes\u6a21\u5757\u3001\u4f7f\u7528memoryview\u5bf9\u8c61<\/strong>\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728Python\u4e2d\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002<\/p>\n<\/p>\n<p><p>\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528<code>ctypes<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002<\/p>\n<\/p>\n<p><p><strong>ctypes\u6a21\u5757\u4ecb\u7ecd<\/strong><\/p>\n<\/p>\n<p><p><code>ctypes<\/code>\u662fPython\u7684\u4e00\u4e2a\u5916\u90e8\u5e93\uff0c\u7528\u6765\u8c03\u7528C\u8bed\u8a00\u7684\u52a8\u6001\u94fe\u63a5\u5e93\uff08DLL\uff09\u3002\u901a\u8fc7<code>ctypes<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e0e\u5e95\u5c42\u5185\u5b58\u8fdb\u884c\u4ea4\u4e92\u3002\u4f7f\u7528<code>ctypes<\/code>\u6a21\u5757\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u53d8\u91cf<\/strong><\/h2>\n<p>a = 10<\/p>\n<h2><strong>\u83b7\u53d6\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740<\/strong><\/h2>\n<p>address = id(a)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3a\u6307\u9488\u7c7b\u578b<\/strong><\/h2>\n<p>pointer = ctypes.cast(address, ctypes.POINTER(ctypes.c_int))<\/p>\n<h2><strong>\u8f93\u51fa\u5185\u5b58\u5730\u5740<\/strong><\/h2>\n<p>print(f&#39;\u5185\u5b58\u5730\u5740\uff1a{address}&#39;)<\/p>\n<p>print(f&#39;\u6307\u9488\u5185\u5bb9\uff1a{pointer.contents.value}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>id()<\/code>\u51fd\u6570\u83b7\u53d6\u53d8\u91cf<code>a<\/code>\u7684\u5185\u5b58\u5730\u5740\uff0c\u7136\u540e\u4f7f\u7528<code>ctypes.cast<\/code>\u5c06\u8fd9\u4e2a\u5730\u5740\u8f6c\u6362\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u5e76\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u53d8\u91cf\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001\u4f7f\u7528id()\u51fd\u6570<\/h2>\n<\/p>\n<p><p><code>id()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u51fd\u6570\uff0c\u8fd4\u56de\u5bf9\u8c61\u7684\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u5373\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002\u8fd9\u4e2a\u51fd\u6570\u901a\u5e38\u7528\u4e8e\u8c03\u8bd5\u548c\u5206\u6790\u5185\u5b58\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 42<\/p>\n<p>address = id(a)<\/p>\n<p>print(f&#39;\u53d8\u91cfa\u7684\u5185\u5b58\u5730\u5740\u662f\uff1a{address}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>id()<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u4efb\u4f55\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPython\u4e2d\u7684\u67d0\u4e9b\u5bf9\u8c61\uff08\u5982\u6574\u6570\u548c\u77ed\u5b57\u7b26\u4e32\uff09\u53ef\u80fd\u4f1a\u88ab\u7f13\u5b58\uff0c\u56e0\u6b64\u5b83\u4eec\u7684\u5185\u5b58\u5730\u5740\u53ef\u80fd\u4f1a\u91cd\u590d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>id()\u51fd\u6570\u7684\u5c40\u9650\u6027<\/h3>\n<\/p>\n<p><p>\u867d\u7136<code>id()<\/code>\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\uff0c\u4f46\u5b83\u5e76\u4e0d\u80fd\u76f4\u63a5\u8ba9\u6211\u4eec\u64cd\u4f5c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>ctypes<\/code>\u6a21\u5757\u6765\u8fdb\u4e00\u6b65\u64cd\u4f5c\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528ctypes\u6a21\u5757<\/h2>\n<\/p>\n<p><p><code>ctypes<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e0eC\u8bed\u8a00\u7c7b\u4f3c\u7684\u6307\u9488\u64cd\u4f5c\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>a = 42<\/p>\n<p>address = id(a)<\/p>\n<p>pointer = ctypes.cast(address, ctypes.POINTER(ctypes.c_int))<\/p>\n<p>print(f&#39;\u53d8\u91cfa\u7684\u5185\u5b58\u5730\u5740\u662f\uff1a{address}&#39;)<\/p>\n<p>print(f&#39;\u6307\u9488\u5185\u5bb9\uff1a{pointer.contents.value}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u901a\u8fc7<code>id()<\/code>\u51fd\u6570\u83b7\u53d6\u53d8\u91cf<code>a<\/code>\u7684\u5185\u5b58\u5730\u5740\uff0c\u7136\u540e\u4f7f\u7528<code>ctypes.cast<\/code>\u5c06\u8fd9\u4e2a\u5730\u5740\u8f6c\u6362\u4e3a\u6307\u9488\u7c7b\u578b\uff0c\u5e76\u901a\u8fc7\u6307\u9488\u8bbf\u95ee\u53d8\u91cf\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u4fee\u6539\u5185\u5b58\u4e2d\u7684\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u6307\u9488\u4fee\u6539\u5185\u5b58\u4e2d\u7684\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>a = 42<\/p>\n<p>address = id(a)<\/p>\n<p>pointer = ctypes.cast(address, ctypes.POINTER(ctypes.c_int))<\/p>\n<p>pointer.contents.value = 84<\/p>\n<p>print(f&#39;\u53d8\u91cfa\u7684\u503c\u662f\uff1a{a}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cPython\u4e2d\u7684\u6574\u6570\u662f\u4e0d\u53ef\u53d8\u7684\u5bf9\u8c61\uff0c\u76f4\u63a5\u4fee\u6539\u5185\u5b58\u4e2d\u7684\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u7684\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528memoryview\u5bf9\u8c61<\/h2>\n<\/p>\n<p><p><code>memoryview<\/code>\u5bf9\u8c61\u7528\u4e8e\u8bbf\u95ee\u6570\u7ec4\u7684\u7f13\u51b2\u533a\u63a5\u53e3\uff0c\u53ef\u4ee5\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u521b\u5efamemoryview\u5bf9\u8c61<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import array<\/p>\n<p>a = array.array(&#39;i&#39;, [1, 2, 3, 4, 5])<\/p>\n<p>m = memoryview(a)<\/p>\n<p>print(f&#39;memoryview\u5bf9\u8c61\u7684\u5185\u5bb9\uff1a{m.tolist()}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>memoryview<\/code>\u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u548c\u4fee\u6539\u6570\u7ec4\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">m[0] = 42<\/p>\n<p>print(f&#39;\u4fee\u6539\u540e\u7684\u6570\u7ec4\uff1a{a}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>memoryview\u5bf9\u8c61\u7684\u9ad8\u7ea7\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>memoryview<\/code>\u5bf9\u8c61\u8fd8\u652f\u6301\u5207\u7247\u64cd\u4f5c\u548c\u591a\u7ef4\u6570\u7ec4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>a = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<p>m = memoryview(a)<\/p>\n<p>print(f&#39;memoryview\u5bf9\u8c61\u7684\u5185\u5bb9\uff1a{m.tolist()}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>memoryview<\/code>\u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\uff0c\u800c\u65e0\u9700\u590d\u5236\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001ctypes\u6a21\u5757\u7684\u9ad8\u7ea7\u7528\u6cd5<\/h2>\n<\/p>\n<p><p><code>ctypes<\/code>\u6a21\u5757\u4e0d\u4ec5\u53ef\u4ee5\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\uff0c\u8fd8\u53ef\u4ee5\u8c03\u7528C\u8bed\u8a00\u7684\u52a8\u6001\u94fe\u63a5\u5e93\uff0c\u8fdb\u884c\u66f4\u590d\u6742\u7684\u5185\u5b58\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u8c03\u7528C\u8bed\u8a00\u51fd\u6570<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>lib = ctypes.CDLL(&#39;.\/mylib.so&#39;)<\/p>\n<p>result = lib.my_function(42)<\/p>\n<p>print(f&#39;C\u8bed\u8a00\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff1a{result}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>ctypes<\/code>\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u8c03\u7528C\u8bed\u8a00\u7684\u51fd\u6570\uff0c\u8fdb\u884c\u66f4\u9ad8\u6548\u7684\u8ba1\u7b97\u548c\u5185\u5b58\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u5b9a\u4e49C\u8bed\u8a00\u7ed3\u6784\u4f53<\/h3>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>ctypes<\/code>\u6a21\u5757\u5b9a\u4e49C\u8bed\u8a00\u7684\u7ed3\u6784\u4f53\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>class MyStruct(ctypes.Structure):<\/p>\n<p>    _fields_ = [(&#39;x&#39;, ctypes.c_int), (&#39;y&#39;, ctypes.c_float)]<\/p>\n<p>s = MyStruct(42, 3.14)<\/p>\n<p>print(f&#39;\u7ed3\u6784\u4f53\u7684\u5185\u5bb9\uff1ax={s.x}, y={s.y}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>ctypes<\/code>\u6a21\u5757\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5b9a\u4e49\u548c\u64cd\u4f5cC\u8bed\u8a00\u7684\u590d\u6742\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5185\u5b58\u7ba1\u7406\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<p><p>\u5728\u64cd\u4f5c\u5185\u5b58\u65f6\uff0c\u6211\u4eec\u9700\u8981\u7279\u522b\u6ce8\u610f\u5185\u5b58\u7ba1\u7406\uff0c\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u548c\u672a\u5b9a\u4e49\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h3>\u907f\u514d\u5185\u5b58\u6cc4\u6f0f<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>ctypes<\/code>\u6a21\u5757\u65f6\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u6240\u6709\u5206\u914d\u7684\u5185\u5b58\u90fd\u88ab\u6b63\u786e\u91ca\u653e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>ptr = ctypes.create_string_buffer(1024)<\/p>\n<h2><strong>\u4f7f\u7528ptr<\/strong><\/h2>\n<p>ctypes.memset(ptr, 0, 1024)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u5728\u4f7f\u7528\u5b8c\u5185\u5b58\u540e\uff0c\u53ca\u65f6\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><h3>\u907f\u514d\u672a\u5b9a\u4e49\u884c\u4e3a<\/h3>\n<\/p>\n<p><p>\u5728\u64cd\u4f5c\u5185\u5b58\u65f6\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u6240\u6709\u7684\u5185\u5b58\u8bbf\u95ee\u90fd\u662f\u5408\u6cd5\u7684\uff0c\u907f\u514d\u672a\u5b9a\u4e49\u884c\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import ctypes<\/p>\n<p>a = 42<\/p>\n<p>address = id(a)<\/p>\n<p>pointer = ctypes.cast(address, ctypes.POINTER(ctypes.c_int))<\/p>\n<p>try:<\/p>\n<p>    pointer.contents.value = 84<\/p>\n<p>except ValueError as e:<\/p>\n<p>    print(f&#39;\u9519\u8bef\uff1a{e}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6b63\u786e\u7684\u5185\u5b58\u7ba1\u7406\uff0c\u6211\u4eec\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u548c\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u4e86\u89e3\u4e86Python\u4e2d\u5982\u4f55\u4f7f\u7528\u53d6\u5740\u7b26\u4ee5\u53ca\u5982\u4f55\u8fdb\u884c\u5185\u5b58\u64cd\u4f5c\u3002\u6211\u4eec\u4e3b\u8981\u63a2\u8ba8\u4e86\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528id()\u51fd\u6570<\/strong>\uff1a\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\uff0c\u9002\u7528\u4e8e\u8c03\u8bd5\u548c\u5206\u6790\u5185\u5b58\u7ba1\u7406\u3002<\/li>\n<li><strong>\u4f7f\u7528ctypes\u6a21\u5757<\/strong>\uff1a\u901a\u8fc7\u6307\u9488\u64cd\u4f5c\u5185\u5b58\uff0c\u9002\u7528\u4e8e\u66f4\u590d\u6742\u7684\u5185\u5b58\u64cd\u4f5c\u548c\u8c03\u7528C\u8bed\u8a00\u7684\u51fd\u6570\u3002<\/li>\n<li><strong>\u4f7f\u7528memoryview\u5bf9\u8c61<\/strong>\uff1a\u76f4\u63a5\u64cd\u4f5c\u6570\u7ec4\u7684\u7f13\u51b2\u533a\u63a5\u53e3\uff0c\u9002\u7528\u4e8e\u9ad8\u6548\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\u3002<\/li>\n<li><strong>\u9ad8\u7ea7\u7528\u6cd5<\/strong>\uff1a\u4f7f\u7528ctypes\u6a21\u5757\u5b9a\u4e49C\u8bed\u8a00\u7ed3\u6784\u4f53\u548c\u8c03\u7528C\u8bed\u8a00\u7684\u51fd\u6570\uff0c\u8fdb\u884c\u66f4\u9ad8\u6548\u7684\u8ba1\u7b97\u548c\u5185\u5b58\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u5185\u5b58\u7ba1\u7406\u7684\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u548c\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\u548c\u4f18\u5316\u7a0b\u5e8f\u6027\u80fd\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u9ad8\u6548\u548c\u7a33\u5b9a\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u53d6\u5740\u7b26\u5728Python\u4e2d\u6709\u4ec0\u4e48\u5177\u4f53\u5e94\u7528\uff1f<\/strong><br \/>\u53d6\u5740\u7b26\uff08&amp;\uff09\u5728Python\u4e2d\u5e76\u4e0d\u76f4\u63a5\u4f7f\u7528\uff0c\u56e0\u4e3aPython\u662f\u4e00\u79cd\u9ad8\u7ea7\u8bed\u8a00\uff0c\u4e0d\u5141\u8bb8\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58\u5730\u5740\u3002Python\u7684\u53d8\u91cf\u5b9e\u9645\u4e0a\u662f\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u64cd\u4f5c\u5bf9\u8c61\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f15\u7528\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u5bf9\u8c61\u7684\u5185\u5bb9\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u5217\u8868\u6216\u5b57\u5178\u7b49\u6570\u636e\u7ed3\u6784\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u7c7b\u4f3c\u53d6\u5740\u7b26\u7684\u529f\u80fd\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u6709\u6548\u7ba1\u7406\u5185\u5b58\u4f7f\u7528\uff1f<\/strong><br \/>Python\u6709\u5185\u7f6e\u7684\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u80fd\u591f\u81ea\u52a8\u7ba1\u7406\u5185\u5b58\u3002\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u5c3d\u91cf\u907f\u514d\u521b\u5efa\u4e0d\u5fc5\u8981\u7684\u5bf9\u8c61\uff0c\u4f7f\u7528\u751f\u6210\u5668\u548c\u8fed\u4ee3\u5668\u53ef\u4ee5\u964d\u4f4e\u5185\u5b58\u4f7f\u7528\u3002\u540c\u65f6\uff0c\u4f7f\u7528<code>del<\/code>\u8bed\u53e5\u53ef\u4ee5\u624b\u52a8\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u5bf9\u8c61\uff0c\u4ece\u800c\u91ca\u653e\u5185\u5b58\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>gc<\/code>\u6a21\u5757\u53ef\u4ee5\u66f4\u7ec6\u81f4\u5730\u63a7\u5236\u548c\u76d1\u89c6\u5185\u5b58\u7684\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6240\u6709\u53d8\u91cf\u90fd\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u5f53\u5c06\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u65f6\uff0c\u5b9e\u9645\u4e0a\u4f20\u9012\u7684\u662f\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u8fd9\u610f\u5473\u7740\u5728\u51fd\u6570\u5185\u90e8\u5bf9\u5bf9\u8c61\u7684\u4fee\u6539\u5c06\u5f71\u54cd\u5230\u5916\u90e8\u53d8\u91cf\u7684\u503c\u3002\u5982\u679c\u5e0c\u671b\u5728\u51fd\u6570\u5185\u90e8\u4e0d\u6539\u53d8\u5916\u90e8\u53d8\u91cf\uff0c\u53ef\u4ee5\u8003\u8651\u4f20\u9012\u5bf9\u8c61\u7684\u526f\u672c\uff0c\u4f8b\u5982\u4f7f\u7528\u5217\u8868\u7684\u5207\u7247\u6216<code>copy<\/code>\u6a21\u5757\u4e2d\u7684<code>copy()<\/code>\u65b9\u6cd5\u3002\u8fd9\u6837\u53ef\u4ee5\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u53d8\u91cf\u7ba1\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u7684\u53d6\u5740\u7b26\uff08address-of operator\uff09\u4e3b\u8981\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u3002\u5728Python\u4e2d\u5e76 [&hellip;]","protected":false},"author":3,"featured_media":1183493,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183485"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1183485"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183485\/revisions"}],"predecessor-version":[{"id":1183494,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183485\/revisions\/1183494"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1183493"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1183485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1183485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1183485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}