{"id":1038246,"date":"2024-12-31T12:22:13","date_gmt":"2024-12-31T04:22:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1038246.html"},"modified":"2024-12-31T12:22:17","modified_gmt":"2024-12-31T04:22:17","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e6%9f%90%e5%80%bc%e6%94%b9%e4%b8%ba%e7%a9%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1038246.html","title":{"rendered":"python\u5982\u4f55\u5c06\u67d0\u503c\u6539\u4e3a\u7a7a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/28fb1a0e-eb82-42c6-9df3-6283e3948daa.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u5c06\u67d0\u503c\u6539\u4e3a\u7a7a\" \/><\/p>\n<p><p> <strong>Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5c06\u67d0\u4e2a\u503c\u6539\u4e3a\u7a7a<\/strong>\uff0c\u4f8b\u5982\uff1a\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u3001\u4f7f\u7528\u7a7a\u5b57\u7b26\u4e32\u3001\u4f7f\u7528\u7a7a\u5217\u8868\u3001\u7a7a\u5b57\u5178\u7b49\u3002\u5177\u4f53\u7684\u65b9\u5f0f\u53d6\u51b3\u4e8e\u4f60\u5e0c\u671b\u5c06\u503c\u6539\u4e3a\u7a7a\u7684\u4e0a\u4e0b\u6587\u3002<strong>\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u5305\u62ec\uff1a\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u3001\u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32&#39;&#39;\u3001\u5c06\u5217\u8868\u6216\u5b57\u5178\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5217\u8868[]\u6216\u7a7a\u5b57\u5178{}<\/strong>\u3002\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u6700\u5e38\u89c1\u7684\u60c5\u51b5\u662f\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\uff0c\u8fd9\u8868\u793a\u8be5\u53d8\u91cf\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\uff0c\u662f\u6700\u901a\u7528\u7684\u7a7a\u503c\u8868\u793a\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u662f\u4e00\u79cd\u5e38\u89c1\u4e14\u6709\u6548\u7684\u65b9\u5f0f\u3002None\u662fPython\u7684\u4e00\u4e2a\u7279\u6b8a\u7684\u5e38\u91cf\uff0c\u7528\u6765\u8868\u793a\u201c\u7a7a\u201d\u6216\u201c\u65e0\u503c\u201d\u3002\u5f53\u4f60\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u65f6\uff0c\u4f60\u5b9e\u9645\u4e0a\u662f\u5728\u544a\u8bc9\u89e3\u91ca\u5668\uff0c\u8fd9\u4e2a\u53d8\u91cf\u73b0\u5728\u4e0d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u663e\u800c\u6613\u89c1\u7684\uff1a\u5b83\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u4f7f\u5f97\u5176\u4ed6\u5f00\u53d1\u8005\u80fd\u591f\u4e00\u76ee\u4e86\u7136\u5730\u660e\u767d\u8fd9\u4e2a\u53d8\u91cf\u5f53\u524d\u6ca1\u6709\u4efb\u4f55\u6709\u610f\u4e49\u7684\u503c\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5728\u4e0d\u540c\u7684\u60c5\u5883\u4e0b\u5c06\u67d0\u4e2a\u503c\u6539\u4e3a\u7a7a\uff0c\u5e76\u8ba8\u8bba\u6bcf\u79cd\u65b9\u6cd5\u7684\u5177\u4f53\u5e94\u7528\u53ca\u5176\u4f18\u7f3a\u70b9\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone<\/h3>\n<\/p>\n<p><p>\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u662fPython\u4e2d\u8868\u793a\u7a7a\u503c\u7684\u6700\u5e38\u89c1\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u7528\u4f8b\uff1a<\/p>\n<\/p>\n<p><h4>1.1\u3001\u666e\u901a\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e2a\u666e\u901a\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u7b80\u5355\u5730\u5c06\u5176\u8d4b\u503c\u4e3aNone\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_var = 42  # \u53d8\u91cf\u521d\u59cb\u503c<\/p>\n<p>my_var = None  # \u5c06\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u53d8\u91cf<code>my_var<\/code>\u8d4b\u503c\u4e3a\u4e00\u4e2a\u6574\u657042\uff0c\u7136\u540e\u901a\u8fc7\u5c06\u5176\u8d4b\u503c\u4e3aNone\u6765\u5c06\u5176\u6539\u4e3a\u7a7a\u503c\u3002\u6b64\u65f6<code>my_var<\/code>\u4e0d\u518d\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>1.2\u3001\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u5c06\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u8d4b\u503c\u4e3aNone\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3, 4]<\/p>\n<p>my_list[2] = None  # \u5c06\u5217\u8868\u4e2d\u7684\u7b2c\u4e09\u4e2a\u5143\u7d20\u6539\u4e3a\u7a7a<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868<code>my_list<\/code>\u7684\u7b2c\u4e09\u4e2a\u5143\u7d20\u88ab\u8d4b\u503c\u4e3aNone\uff0c\u4ece\u800c\u8868\u793a\u8fd9\u4e2a\u4f4d\u7f6e\u4e0a\u6ca1\u6709\u6709\u6548\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u53d8\u91cf\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u8d4b\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32<code>&#39;&#39;<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;Hello, World!&quot;<\/p>\n<p>my_string = &#39;&#39;  # \u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u6539\u4e3a\u7a7a\u5b57\u7b26\u4e32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32\u662f\u975e\u5e38\u76f4\u89c2\u7684\u65b9\u6cd5\uff0c\u5b83\u8868\u793a\u8fd9\u4e2a\u53d8\u91cf\u73b0\u5728\u662f\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5c06\u5217\u8868\u6216\u5b57\u5178\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5217\u8868\u6216\u7a7a\u5b57\u5178<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5217\u8868\u6216\u5b57\u5178\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u4f60\u53ef\u4ee5\u5c06\u5176\u8d4b\u503c\u4e3a\u7a7a\u5217\u8868<code>[]<\/code>\u6216\u7a7a\u5b57\u5178<code>{}<\/code>\uff1a<\/p>\n<\/p>\n<p><h4>3.1\u3001\u7a7a\u5217\u8868<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">my_list = [1, 2, 3]<\/p>\n<p>my_list = []  # \u5c06\u5217\u8868\u53d8\u91cf\u6539\u4e3a\u7a7a\u5217\u8868<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2\u3001\u7a7a\u5b57\u5178<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2}<\/p>\n<p>my_dict = {}  # \u5c06\u5b57\u5178\u53d8\u91cf\u6539\u4e3a\u7a7a\u5b57\u5178<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u5217\u8868\u6216\u5b57\u5178\u53d8\u91cf\u8d4b\u503c\u4e3a\u7a7a\u5217\u8868\u6216\u7a7a\u5b57\u5178\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u91cd\u7f6e\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u65f6\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5728\u51fd\u6570\u53c2\u6570\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\uff0c\u4f7f\u7528None\u4f5c\u4e3a\u9ed8\u8ba4\u53c2\u6570\u503c\u4e5f\u662f\u4e00\u79cd\u5f88\u5e38\u89c1\u7684\u505a\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def my_function(param=None):<\/p>\n<p>    if param is None:<\/p>\n<p>        param = []<\/p>\n<p>    # \u7ee7\u7eed\u5904\u7406param<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u4f60\u5728\u51fd\u6570\u5185\u90e8\u5224\u65ad\u53c2\u6570\u662f\u5426\u88ab\u63d0\u4f9b\uff0c\u5e76\u6839\u636e\u9700\u8981\u521d\u59cb\u5316\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5728\u7c7b\u5c5e\u6027\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\uff0c\u521d\u59cb\u5316\u7c7b\u5c5e\u6027\u65f6\u4e5f\u53ef\u4ee5\u4f7f\u7528None\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class MyClass:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.my_attr = None<\/p>\n<p>    def set_attr(self, value):<\/p>\n<p>        self.my_attr = value<\/p>\n<p>    def clear_attr(self):<\/p>\n<p>        self.my_attr = None<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u5f97\u7c7b\u7684\u5c5e\u6027\u521d\u59cb\u5316\u66f4\u52a0\u660e\u786e\uff0c\u5e76\u4e14\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528del\u8bed\u53e5\u5220\u9664\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>del<\/code>\u8bed\u53e5\u5220\u9664\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_var = 42<\/p>\n<p>del my_var  # \u5220\u9664\u53d8\u91cf<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5220\u9664\u53d8\u91cf\u540e\uff0c\u518d\u6b21\u8bbf\u95ee\u8be5\u53d8\u91cf\u5c06\u5f15\u53d1<code>NameError<\/code>\u9519\u8bef\uff0c\u56e0\u4e3a\u8be5\u53d8\u91cf\u4e0d\u518d\u5b58\u5728\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5728\u6570\u636e\u6846\u4e2d\u5c06\u67d0\u5217\u503c\u6539\u4e3a\u7a7a<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6570\u636e\u6846\u65f6\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u67d0\u5217\u7684\u503c\u6539\u4e3a\u7a7a\u3002\u8fd9\u901a\u5e38\u4f7f\u7528Pandas\u5e93\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<p>df = pd.DataFrame({&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]})<\/p>\n<p>df[&#39;A&#39;] = np.nan  # \u5c06\u5217&#39;A&#39;\u7684\u503c\u6539\u4e3a\u7a7a<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>np.nan<\/code>\u6765\u8868\u793a\u6570\u636e\u6846\u4e2d\u7684\u7a7a\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u5c06\u67d0\u5b57\u6bb5\u503c\u6539\u4e3a\u7a7a<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5c06\u67d0\u4e2a\u5b57\u6bb5\u7684\u503c\u6539\u4e3a\u7a7a\u3002\u5728SQL\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>NULL<\/code>\u6765\u8868\u793a\u7a7a\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sql\">UPDATE my_table SET my_column = NULL WHERE condition;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6570\u636e\u5e93\u9a71\u52a8\u7a0b\u5e8f\uff08\u5982<code>sqlite3<\/code>\u3001<code>psycopg2<\/code>\u7b49\uff09\u6765\u6267\u884c\u8fd9\u6837\u7684SQL\u8bed\u53e5\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u5728\u96c6\u5408\u548c\u5143\u7ec4\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u96c6\u5408\u548c\u5143\u7ec4\u4e2d\u7684\u5143\u7d20\u901a\u5e38\u4e0d\u9700\u8981\u6539\u4e3a\u7a7a\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u91cd\u65b0\u521d\u59cb\u5316\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\uff1a<\/p>\n<\/p>\n<p><h4>9.1\u3001\u96c6\u5408<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">my_set = {1, 2, 3}<\/p>\n<p>my_set = set()  # \u5c06\u96c6\u5408\u6539\u4e3a\u7a7a\u96c6\u5408<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>9.2\u3001\u5143\u7ec4<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">my_tuple = (1, 2, 3)<\/p>\n<p>my_tuple = ()  # \u5c06\u5143\u7ec4\u6539\u4e3a\u7a7a\u5143\u7ec4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u5728\u5d4c\u5957\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u5d4c\u5957\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u9012\u5f52\u7684\u65b9\u6cd5\u5c06\u67d0\u4e2a\u503c\u6539\u4e3a\u7a7a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def clear_nested_value(data, target_value):<\/p>\n<p>    if isinstance(data, list):<\/p>\n<p>        for i in range(len(data)):<\/p>\n<p>            if data[i] == target_value:<\/p>\n<p>                data[i] = None<\/p>\n<p>            elif isinstance(data[i], (list, dict)):<\/p>\n<p>                clear_nested_value(data[i], target_value)<\/p>\n<p>    elif isinstance(data, dict):<\/p>\n<p>        for key, value in data.items():<\/p>\n<p>            if value == target_value:<\/p>\n<p>                data[key] = None<\/p>\n<p>            elif isinstance(value, (list, dict)):<\/p>\n<p>                clear_nested_value(value, target_value)<\/p>\n<p>nested_data = {&#39;a&#39;: [1, 2, {&#39;b&#39;: 3}], &#39;c&#39;: 4}<\/p>\n<p>clear_nested_value(nested_data, 2)<\/p>\n<p>print(nested_data)  # {&#39;a&#39;: [1, None, {&#39;b&#39;: 3}], &#39;c&#39;: 4}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u9012\u5f52\u51fd\u6570<code>clear_nested_value<\/code>\uff0c\u5b83\u53ef\u4ee5\u5c06\u5d4c\u5957\u6570\u636e\u7ed3\u6784\u4e2d\u5339\u914d\u7684\u503c\u6539\u4e3a\u7a7a\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u591a\u79cd\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u7075\u6d3b\u5730\u5c06Python\u4e2d\u7684\u67d0\u4e2a\u503c\u6539\u4e3a\u7a7a\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u548c\u6570\u636e\u7c7b\u578b\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u7406\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\u5c06\u5e2e\u52a9\u4f60\u7f16\u5199\u66f4\u52a0\u5065\u58ee\u548c\u6613\u4e8e\u7ef4\u62a4\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u53d8\u91cf\u7684\u503c\u8bbe\u7f6e\u4e3a\u7a7a\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3a<code>None<\/code>\u6765\u5c06\u5176\u503c\u8bbe\u7f6e\u4e3a\u7a7a\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u53d8\u91cf<code>x<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528<code>x = None<\/code>\u6765\u5b9e\u73b0\u3002<code>None<\/code>\u662fPython\u4e2d\u7684\u4e00\u4e2a\u7279\u6b8a\u5bf9\u8c61\uff0c\u8868\u793a\u201c\u65e0\u503c\u201d\u6216\u201c\u7a7a\u201d\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u6e05\u7a7a\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u7279\u5b9a\u5143\u7d20\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u5e0c\u671b\u4ece\u5217\u8868\u4e2d\u79fb\u9664\u67d0\u4e2a\u7279\u5b9a\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528<code>remove()<\/code>\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u5217\u8868<code>my_list = [1, 2, 3, 4]<\/code>\uff0c\u5e76\u60f3\u5c06\u503c<code>3<\/code>\u6539\u4e3a\u7a7a\uff0c\u53ef\u4ee5\u5148\u7528<code>my_list.remove(3)<\/code>\u5c06\u5176\u79fb\u9664\u3002\u8fd9\u6837\uff0c\u5217\u8868\u5c06\u53d8\u4e3a<code>[1, 2, 4]<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u5b57\u5178\u4e2d\u5c06\u67d0\u4e2a\u952e\u7684\u503c\u6539\u4e3a\u7a7a\uff1f<\/strong><br \/>\u5bf9\u4e8e\u5b57\u5178\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u7279\u5b9a\u952e\u7684\u503c\u8bbe\u7f6e\u4e3a<code>None<\/code>\u6765\u5c06\u5176\u6539\u4e3a\u7a7a\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5b57\u5178<code>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2}<\/code>\uff0c\u5982\u679c\u60f3\u5c06\u952e<code>&#39;a&#39;<\/code>\u7684\u503c\u6539\u4e3a\u7a7a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>my_dict[&#39;a&#39;] = None<\/code>\uff0c\u6b64\u65f6\u5b57\u5178\u5c06\u53d8\u4e3a<code>{&#39;a&#39;: None, &#39;b&#39;: 2}<\/code>\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u8868\u793a\u8be5\u952e\u5f53\u524d\u6ca1\u6709\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5c06\u67d0\u4e2a\u503c\u6539\u4e3a\u7a7a\uff0c\u4f8b\u5982\uff1a\u5c06\u53d8\u91cf\u8d4b\u503c\u4e3aNone\u3001\u4f7f\u7528\u7a7a\u5b57\u7b26\u4e32\u3001\u4f7f\u7528\u7a7a\u5217\u8868\u3001\u7a7a\u5b57\u5178\u7b49\u3002\u5177 [&hellip;]","protected":false},"author":3,"featured_media":1038264,"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\/1038246"}],"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=1038246"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038246\/revisions"}],"predecessor-version":[{"id":1038266,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038246\/revisions\/1038266"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1038264"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1038246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1038246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1038246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}