{"id":1029469,"date":"2024-12-31T11:08:29","date_gmt":"2024-12-31T03:08:29","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1029469.html"},"modified":"2024-12-31T11:08:31","modified_gmt":"2024-12-31T03:08:31","slug":"python%e5%ae%9e%e9%aa%8c%e6%8a%a5%e5%91%8a%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%ad%97%e5%85%b8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1029469.html","title":{"rendered":"python\u5b9e\u9a8c\u62a5\u544a\u5982\u4f55\u4f7f\u7528\u5b57\u5178"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/2101838a-8460-4413-b8c8-899c246e835c.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5b9e\u9a8c\u62a5\u544a\u5982\u4f55\u4f7f\u7528\u5b57\u5178\" \/><\/p>\n<p><h2>PYTHON\u5b9e\u9a8c\u62a5\u544a\u5982\u4f55\u4f7f\u7528\u5b57\u5178<\/h2>\n<\/p>\n<p><p><strong>Python\u5b57\u5178\u662f\u4e00\u79cd\u7528\u4e8e\u5b58\u50a8\u5177\u6709\u552f\u4e00\u952e\u7684\u952e\u503c\u5bf9\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u4eec\u662f\u65e0\u5e8f\u7684\u3001\u53ef\u53d8\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728O(1)\u65f6\u95f4\u5185\u8fdb\u884c\u67e5\u627e\u3002\u5b57\u5178\u5728\u5b58\u50a8\u548c\u5904\u7406\u52a8\u6001\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3001\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u68c0\u7d22\u3001\u5141\u8bb8\u4f7f\u7528\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\u4f5c\u4e3a\u952e\u3002<\/strong> \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bbaPython\u5b57\u5178\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u62ec\u5982\u4f55\u521b\u5efa\u5b57\u5178\u3001\u8bbf\u95ee\u5b57\u5178\u5143\u7d20\u3001\u4fee\u6539\u5b57\u5178\u3001\u5220\u9664\u5143\u7d20\u4ee5\u53ca\u5b57\u5178\u7684\u5e38\u89c1\u64cd\u4f5c\u548c\u5e94\u7528\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u521b\u5efa\u5b57\u5178<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u82b1\u62ec\u53f7 <code>{}<\/code> \u6216\u8005 <code>dict()<\/code> \u51fd\u6570\u521b\u5efa\u5b57\u5178\u3002\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f\u552f\u4e00\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u662f\u4efb\u4f55\u4e0d\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u82b1\u62ec\u53f7\u521b\u5efa\u5b57\u5178<\/p>\n<p>my_dict = {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;New York&#39;}<\/p>\n<h2><strong>\u4f7f\u7528dict()\u51fd\u6570\u521b\u5efa\u5b57\u5178<\/strong><\/h2>\n<p>my_dict2 = dict(name=&#39;Bob&#39;, age=30, city=&#39;Los Angeles&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e24\u4e2a\u5b57\u5178 <code>my_dict<\/code> \u548c <code>my_dict2<\/code>\uff0c\u5b83\u4eec\u5206\u522b\u5305\u542b\u4e09\u4e2a\u952e\u503c\u5bf9\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u8bbf\u95ee\u5b57\u5178\u5143\u7d20<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u952e\u6765\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u503c\u3002\u5982\u679c\u952e\u4e0d\u5b58\u5728\uff0c\u4f1a\u5f15\u53d1 <code>KeyError<\/code> \u5f02\u5e38\u3002\u4e3a\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>get()<\/code> \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5728\u952e\u4e0d\u5b58\u5728\u65f6\u8fd4\u56de <code>None<\/code> \u6216\u9ed8\u8ba4\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bbf\u95ee\u5b57\u5178\u5143\u7d20<\/p>\n<p>name = my_dict[&#39;name&#39;]<\/p>\n<p>print(name)  # \u8f93\u51fa: Alice<\/p>\n<h2><strong>\u4f7f\u7528get()\u65b9\u6cd5<\/strong><\/h2>\n<p>age = my_dict.get(&#39;age&#39;)<\/p>\n<p>print(age)  # \u8f93\u51fa: 25<\/p>\n<h2><strong>\u4f7f\u7528get()\u65b9\u6cd5\u5e76\u63d0\u4f9b\u9ed8\u8ba4\u503c<\/strong><\/h2>\n<p>country = my_dict.get(&#39;country&#39;, &#39;USA&#39;)<\/p>\n<p>print(country)  # \u8f93\u51fa: USA<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4fee\u6539\u5b57\u5178<\/h3>\n<\/p>\n<p><p>\u5b57\u5178\u662f\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u53ef\u4ee5\u6dfb\u52a0\u3001\u4fee\u6539\u6216\u5220\u9664\u5176\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6dfb\u52a0\u6216\u4fee\u6539\u5143\u7d20<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u952e\u503c\u5bf9\u7684\u65b9\u5f0f\u6dfb\u52a0\u65b0\u5143\u7d20\u6216\u4fee\u6539\u73b0\u6709\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6dfb\u52a0\u65b0\u5143\u7d20<\/p>\n<p>my_dict[&#39;country&#39;] = &#39;USA&#39;<\/p>\n<p>print(my_dict)  # \u8f93\u51fa: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;New York&#39;, &#39;country&#39;: &#39;USA&#39;}<\/p>\n<h2><strong>\u4fee\u6539\u73b0\u6709\u5143\u7d20<\/strong><\/h2>\n<p>my_dict[&#39;age&#39;] = 26<\/p>\n<p>print(my_dict)  # \u8f93\u51fa: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 26, &#39;city&#39;: &#39;New York&#39;, &#39;country&#39;: &#39;USA&#39;}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5220\u9664\u5143\u7d20<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>del<\/code> \u8bed\u53e5\u6216 <code>pop()<\/code> \u65b9\u6cd5\u5220\u9664\u5b57\u5178\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528del\u8bed\u53e5\u5220\u9664\u5143\u7d20<\/p>\n<p>del my_dict[&#39;city&#39;]<\/p>\n<p>print(my_dict)  # \u8f93\u51fa: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 26, &#39;country&#39;: &#39;USA&#39;}<\/p>\n<h2><strong>\u4f7f\u7528pop()\u65b9\u6cd5\u5220\u9664\u5143\u7d20<\/strong><\/h2>\n<p>age = my_dict.pop(&#39;age&#39;)<\/p>\n<p>print(age)  # \u8f93\u51fa: 26<\/p>\n<p>print(my_dict)  # \u8f93\u51fa: {&#39;name&#39;: &#39;Alice&#39;, &#39;country&#39;: &#39;USA&#39;}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b57\u5178\u7684\u5e38\u89c1\u64cd\u4f5c<\/h3>\n<\/p>\n<p><h4>1\u3001\u83b7\u53d6\u5b57\u5178\u7684\u952e\u3001\u503c\u548c\u952e\u503c\u5bf9<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>keys()<\/code>\u3001<code>values()<\/code> \u548c <code>items()<\/code> \u65b9\u6cd5\u5206\u522b\u83b7\u53d6\u5b57\u5178\u7684\u952e\u3001\u503c\u548c\u952e\u503c\u5bf9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u5b57\u5178\u7684\u952e<\/p>\n<p>keys = my_dict.keys()<\/p>\n<p>print(keys)  # \u8f93\u51fa: dict_keys([&#39;name&#39;, &#39;country&#39;])<\/p>\n<h2><strong>\u83b7\u53d6\u5b57\u5178\u7684\u503c<\/strong><\/h2>\n<p>values = my_dict.values()<\/p>\n<p>print(values)  # \u8f93\u51fa: dict_values([&#39;Alice&#39;, &#39;USA&#39;])<\/p>\n<h2><strong>\u83b7\u53d6\u5b57\u5178\u7684\u952e\u503c\u5bf9<\/strong><\/h2>\n<p>items = my_dict.items()<\/p>\n<p>print(items)  # \u8f93\u51fa: dict_items([(&#39;name&#39;, &#39;Alice&#39;), (&#39;country&#39;, &#39;USA&#39;)])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u904d\u5386\u5b57\u5178<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>for<\/code> \u5faa\u73af\u904d\u5386\u5b57\u5178\u7684\u952e\u3001\u503c\u6216\u952e\u503c\u5bf9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u904d\u5386\u5b57\u5178\u7684\u952e<\/p>\n<p>for key in my_dict:<\/p>\n<p>    print(key, my_dict[key])<\/p>\n<h2><strong>\u904d\u5386\u5b57\u5178\u7684\u503c<\/strong><\/h2>\n<p>for value in my_dict.values():<\/p>\n<p>    print(value)<\/p>\n<h2><strong>\u904d\u5386\u5b57\u5178\u7684\u952e\u503c\u5bf9<\/strong><\/h2>\n<p>for key, value in my_dict.items():<\/p>\n<p>    print(key, value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5408\u5e76\u5b57\u5178<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>update()<\/code> \u65b9\u6cd5\u5c06\u4e00\u4e2a\u5b57\u5178\u7684\u5143\u7d20\u6dfb\u52a0\u5230\u53e6\u4e00\u4e2a\u5b57\u5178\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u53e6\u4e00\u4e2a\u5b57\u5178<\/p>\n<p>my_dict2 = {&#39;profession&#39;: &#39;Engineer&#39;, &#39;hobby&#39;: &#39;Reading&#39;}<\/p>\n<h2><strong>\u5408\u5e76\u5b57\u5178<\/strong><\/h2>\n<p>my_dict.update(my_dict2)<\/p>\n<p>print(my_dict)  # \u8f93\u51fa: {&#39;name&#39;: &#39;Alice&#39;, &#39;country&#39;: &#39;USA&#39;, &#39;profession&#39;: &#39;Engineer&#39;, &#39;hobby&#39;: &#39;Reading&#39;}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5b57\u5178\u7684\u5e94\u7528\u793a\u4f8b<\/h3>\n<\/p>\n<p><h4>1\u3001\u7edf\u8ba1\u5b57\u7b26\u51fa\u73b0\u6b21\u6570<\/h4>\n<\/p>\n<p><p>\u5b57\u5178\u53ef\u4ee5\u7528\u4e8e\u7edf\u8ba1\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def count_characters(s):<\/p>\n<p>    char_count = {}<\/p>\n<p>    for char in s:<\/p>\n<p>        if char in char_count:<\/p>\n<p>            char_count[char] += 1<\/p>\n<p>        else:<\/p>\n<p>            char_count[char] = 1<\/p>\n<p>    return char_count<\/p>\n<p>string = &quot;hello world&quot;<\/p>\n<p>char_count = count_characters(string)<\/p>\n<p>print(char_count)  # \u8f93\u51fa: {&#39;h&#39;: 1, &#39;e&#39;: 1, &#39;l&#39;: 3, &#39;o&#39;: 2, &#39; &#39;: 1, &#39;w&#39;: 1, &#39;r&#39;: 1, &#39;d&#39;: 1}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7ffb\u8f6c\u5b57\u5178\u7684\u952e\u548c\u503c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u6765\u7ffb\u8f6c\u5b57\u5178\u7684\u952e\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5b57\u5178<\/p>\n<p>original_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<h2><strong>\u7ffb\u8f6c\u5b57\u5178\u7684\u952e\u548c\u503c<\/strong><\/h2>\n<p>reversed_dict = {value: key for key, value in original_dict.items()}<\/p>\n<p>print(reversed_dict)  # \u8f93\u51fa: {1: &#39;a&#39;, 2: &#39;b&#39;, 3: &#39;c&#39;}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5b57\u5178\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u6765\u4f20\u9012\u51fd\u6570\u7684\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def display_info(name, age, city):<\/p>\n<p>    print(f&quot;Name: {name}, Age: {age}, City: {city}&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5b57\u5178<\/strong><\/h2>\n<p>info = {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;New York&#39;}<\/p>\n<h2><strong>\u4f7f\u7528\u5b57\u5178\u4f20\u9012\u53c2\u6570<\/strong><\/h2>\n<p>display_info(info)  # \u8f93\u51fa: Name: Alice, Age: 25, City: New York<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u5b57\u5178\u7684\u9ad8\u7ea7\u7528\u6cd5<\/h3>\n<\/p>\n<p><h4>1\u3001\u5d4c\u5957\u5b57\u5178<\/h4>\n<\/p>\n<p><p>\u5b57\u5178\u53ef\u4ee5\u5305\u542b\u5176\u4ed6\u5b57\u5178\u4f5c\u4e3a\u5176\u503c\uff0c\u8fd9\u79f0\u4e3a\u5d4c\u5957\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u5d4c\u5957\u5b57\u5178<\/p>\n<p>nested_dict = {<\/p>\n<p>    &#39;person1&#39;: {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25},<\/p>\n<p>    &#39;person2&#39;: {&#39;name&#39;: &#39;Bob&#39;, &#39;age&#39;: 30}<\/p>\n<p>}<\/p>\n<h2><strong>\u8bbf\u95ee\u5d4c\u5957\u5b57\u5178\u7684\u5143\u7d20<\/strong><\/h2>\n<p>print(nested_dict[&#39;person1&#39;][&#39;name&#39;])  # \u8f93\u51fa: Alice<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5b57\u5178\u7684\u9ed8\u8ba4\u503c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>collections.defaultdict<\/code> \u4e3a\u5b57\u5178\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2adefaultdict<\/strong><\/h2>\n<p>default_dict = defaultdict(int)<\/p>\n<h2><strong>\u8bbf\u95ee\u4e0d\u5b58\u5728\u7684\u952e\u5c06\u8fd4\u56de\u9ed8\u8ba4\u503c<\/strong><\/h2>\n<p>print(default_dict[&#39;key&#39;])  # \u8f93\u51fa: 0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5b57\u5178\u7684\u6709\u5e8f\u6027<\/h4>\n<\/p>\n<p><p>\u5728Python 3.7\u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0c\u5b57\u5178\u4fdd\u6301\u63d2\u5165\u987a\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>collections.OrderedDict<\/code> \u6765\u786e\u4fdd\u5728\u65e7\u7248\u672c\u4e2d\u4e5f\u80fd\u4fdd\u6301\u987a\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import OrderedDict<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aOrderedDict<\/strong><\/h2>\n<p>ordered_dict = OrderedDict()<\/p>\n<p>ordered_dict[&#39;a&#39;] = 1<\/p>\n<p>ordered_dict[&#39;b&#39;] = 2<\/p>\n<p>ordered_dict[&#39;c&#39;] = 3<\/p>\n<p>print(ordered_dict)  # \u8f93\u51fa: OrderedDict([(&#39;a&#39;, 1), (&#39;b&#39;, 2), (&#39;c&#39;, 3)])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86Python\u5b57\u5178\u7684\u521b\u5efa\u3001\u8bbf\u95ee\u3001\u4fee\u6539\u3001\u5220\u9664\u548c\u5e38\u89c1\u64cd\u4f5c\uff0c\u540c\u65f6\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5e94\u7528\u793a\u4f8b\u548c\u9ad8\u7ea7\u7528\u6cd5\u3002<strong>Python\u5b57\u5178\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u5904\u7406\u6570\u636e<\/strong>\u3002\u901a\u8fc7\u638c\u63e1\u5b57\u5178\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u7f16\u5199Python\u4ee3\u7801\uff0c\u89e3\u51b3\u5404\u79cd\u5b9e\u9645\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u5b9e\u9a8c\u62a5\u544a\u4e2d\u6709\u6548\u5730\u4f7f\u7528\u5b57\u5178\uff1f<\/strong><br \/>\u5728Python\u5b9e\u9a8c\u62a5\u544a\u4e2d\uff0c\u5b57\u5178\u662f\u4e00\u79cd\u975e\u5e38\u7075\u6d3b\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b58\u50a8\u548c\u7ec4\u7ec7\u5b9e\u9a8c\u6570\u636e\u3002\u4f7f\u7528\u5b57\u5178\uff0c\u53ef\u4ee5\u5c06\u5b9e\u9a8c\u7684\u4e0d\u540c\u53c2\u6570\u548c\u7ed3\u679c\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u8fdb\u884c\u5173\u8054\uff0c\u4f7f\u5f97\u6570\u636e\u7684\u8bbf\u95ee\u548c\u4fee\u6539\u66f4\u52a0\u9ad8\u6548\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u5b58\u50a8\u6bcf\u4e2a\u5b9e\u9a8c\u7684\u540d\u79f0\u3001\u65e5\u671f\u3001\u53c2\u6570\u548c\u7ed3\u679c\uff0c\u65b9\u4fbf\u540e\u7eed\u7684\u6570\u636e\u5206\u6790\u548c\u5c55\u793a\u3002<\/p>\n<p><strong>\u5b57\u5178\u5728\u5b9e\u9a8c\u6570\u636e\u7ba1\u7406\u4e2d\u6709\u54ea\u4e9b\u5177\u4f53\u5e94\u7528\uff1f<\/strong><br \/>\u5b57\u5178\u5728\u5b9e\u9a8c\u6570\u636e\u7ba1\u7406\u4e2d\u53ef\u4ee5\u7528\u4e8e\u591a\u79cd\u5e94\u7528\u573a\u666f\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u7528\u5b57\u5178\u6765\u8bb0\u5f55\u5b9e\u9a8c\u4e2d\u7684\u4e0d\u540c\u6d4b\u91cf\u6570\u636e\u3002\u6bcf\u4e2a\u5b9e\u9a8c\u7684\u7ed3\u679c\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u5178\u7684\u503c\uff0c\u800c\u5b9e\u9a8c\u7684\u76f8\u5173\u4fe1\u606f\u5982\u5b9e\u9a8c\u7f16\u53f7\u3001\u65e5\u671f\u7b49\u53ef\u4ee5\u4f5c\u4e3a\u952e\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u5d4c\u5957\u5b57\u5178\u7684\u65b9\u5f0f\u6765\u7ba1\u7406\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u6bd4\u5982\u5c06\u5b9e\u9a8c\u53c2\u6570\u548c\u7ed3\u679c\u5206\u5c42\u5b58\u50a8\uff0c\u4ee5\u4fbf\u4e8e\u6570\u636e\u7684\u5206\u7c7b\u548c\u68c0\u7d22\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u548c\u64cd\u4f5c\u5b57\u5178\u4ee5\u652f\u6301\u5b9e\u9a8c\u62a5\u544a\u7684\u7f16\u5199\uff1f<\/strong><br \/>\u5728Python\u4e2d\u521b\u5efa\u5b57\u5178\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528\u82b1\u62ec\u53f7\u6216<code>dict()<\/code>\u51fd\u6570\u3002\u53ef\u4ee5\u4f7f\u7528\u952e\u503c\u5bf9\u6765\u6dfb\u52a0\u6570\u636e\uff0c\u4f8b\u5982<code>experiment_data = {&#39;experiment_1&#39;: {&#39;date&#39;: &#39;2023-01-01&#39;, &#39;result&#39;: 95}}<\/code>\u3002\u5bf9\u4e8e\u5b57\u5178\u7684\u64cd\u4f5c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5e38\u7528\u7684\u65b9\u6cd5\u5982<code>keys()<\/code>\u3001<code>values()<\/code>\u548c<code>items()<\/code>\u6765\u904d\u5386\u5b57\u5178\u4e2d\u7684\u6570\u636e\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u5b57\u5178\u7684\u66f4\u65b0\u548c\u5220\u9664\u529f\u80fd\uff0c\u53ef\u4ee5\u7075\u6d3b\u5730\u7ba1\u7406\u5b9e\u9a8c\u8bb0\u5f55\uff0c\u786e\u4fdd\u5b9e\u9a8c\u62a5\u544a\u4e2d\u7684\u6570\u636e\u59cb\u7ec8\u4fdd\u6301\u6700\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"PYTHON\u5b9e\u9a8c\u62a5\u544a\u5982\u4f55\u4f7f\u7528\u5b57\u5178 Python\u5b57\u5178\u662f\u4e00\u79cd\u7528\u4e8e\u5b58\u50a8\u5177\u6709\u552f\u4e00\u952e\u7684\u952e\u503c\u5bf9\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u4eec\u662f\u65e0\u5e8f\u7684\u3001\u53ef [&hellip;]","protected":false},"author":3,"featured_media":1029477,"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\/1029469"}],"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=1029469"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1029469\/revisions"}],"predecessor-version":[{"id":1029481,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1029469\/revisions\/1029481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1029477"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1029469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1029469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1029469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}