{"id":68227,"date":"2026-01-29T21:57:27","date_gmt":"2026-01-29T13:57:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/68227.html"},"modified":"2026-01-29T21:57:27","modified_gmt":"2026-01-29T13:57:27","slug":"python%e5%ad%a6%e4%b9%a0%e4%b9%8b%e8%b7%af-%e5%ad%97%e5%85%b8dictionary%e5%ad%a6%e4%b9%a0%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/68227.html","title":{"rendered":"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3"},"content":{"rendered":"<p style=\"text-align:center\">\u6539\u53d8\u4ece\u4e0d\u662f\u4e00\u8e74\u800c\u5c31&#xff0c;\u800c\u662f\u65e5\u79ef\u6708\u7d2f\u7684\u4fee\u6b63\u3002\u4eca\u5929\u7684\u81ea\u5f8b&#xff0c;\u662f\u660e\u5929\u7684\u81ea\u7531\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u5b66\u4e60\u6253\u5361\u7b2c\u5341\u4e09\u5929<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u5728 Python \u4e2d&#xff0c;\u5b57\u5178&#xff08;Dictionary&#xff09;\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u53ef\u53d8\u5bb9\u5668\u6a21\u578b&#xff0c;\u5b83\u80fd\u591f\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u5728\u6570\u636e\u5904\u7406\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u573a\u666f\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002<\/span><\/p>\n<h2 style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u4e00\u3001\u5b57\u5178\u7684\u57fa\u672c\u6982\u5ff5<\/span><\/h2>\n<p>\u5b57\u5178\u7531\u4e00\u7cfb\u5217<span style=\"color:#fe2c24\">\u952e\u503c\u5bf9(<\/span><span style=\"color:#fe2c24\">key:value<\/span>&#xff09;\u7ec4\u6210&#xff0c;\u5176\u57fa\u672c\u683c\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p>dic\u00a0&#061; {key1: value1, key2: value2, key3: value3}<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u952e\u503c\u5bf9\u7528\u5192\u53f7&#xff08;:&#xff09;\u5206\u5272<\/li>\n<li>\u4e0d\u540c\u952e\u503c\u5bf9\u4e4b\u95f4\u7528\u9017\u53f7&#xff08;,&#xff09;\u5206\u9694<\/li>\n<li>\u6574\u4e2a\u5b57\u5178\u5305\u542b\u5728\u82b1\u62ec\u53f7&#xff08;{}&#xff09;\u4e2d<\/li>\n<li><span style=\"color:#fe2c24\">\u952e&#xff08;key&#xff09;\u5fc5\u987b\u662f\u552f\u4e00\u7684<\/span>&#xff0c;\u800c\u503c&#xff08;value&#xff09;\u53ef\u4ee5\u91cd\u590d<\/li>\n<li>\u503c\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b&#xff0c;\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5217\u8868\u3001\u5b57\u5178\u7b49&#xff0c;\u4f46<span style=\"color:#fe2c24\">\u952e\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8<\/span>\u7684&#xff0c;\u4f8b\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5143\u7ec4\u7b49&#xff0c;\u5217\u8868\u7b49\u53ef\u53d8\u7c7b\u578b\u4e0d\u80fd\u4f5c\u4e3a\u952e\u3002<\/li>\n<\/ul>\n<h2 style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u4e8c\u3001\u521b\u5efa\u5b57\u5178<\/span><\/h2>\n<h3>1.\u4f7f\u7528\u5927\u62ec\u53f7&#xff08;{}&#xff09;\u521b\u5efa<\/h3>\n<p>\u8fd9\u662f\u6700\u5e38\u7528\u7684\u521b\u5efa\u5b57\u5178\u7684\u65b9\u5f0f&#xff0c;\u65e2\u53ef\u4ee5\u521b\u5efa\u7a7a\u5b57\u5178&#xff0c;\u4e5f\u53ef\u4ee5\u521b\u5efa\u5305\u542b\u952e\u503c\u5bf9\u7684\u5b57\u5178<\/p>\n<p># \u521b\u5efa\u7a7a\u5b57\u5178<br \/>\nempty_dict &#061; {}<\/p>\n<p># \u521b\u5efa\u5305\u542b\u952e\u503c\u5bf9\u7684\u5b57\u5178<br \/>\nsample_dict &#061; {<br \/>\n    &#034;name&#034;: &#034;\u4e54\u5cf0&#034;,<br \/>\n    &#034;age&#034;: 24,<br \/>\n    &#034;city&#034;: &#034;\u4e10\u5e2e&#034;<br \/>\n}<\/p>\n<p>print(&#034;\u7a7a\u5b57\u5178:&#034;, empty_dict)<br \/>\nprint(&#034;\u5305\u542b\u952e\u503c\u5bf9\u7684\u5b57\u5178:&#034;, sample_dict)<\/p>\n<h3>2.\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u00a0dict()\u00a0\u521b\u5efa<\/h3>\n<p>dict()\u00a0\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u5b57\u5178&#xff0c;\u540c\u6837\u53ef\u4ee5\u521b\u5efa\u7a7a\u5b57\u5178\u6216\u5e26\u6709\u952e\u503c\u5bf9\u7684\u5b57\u5178<\/p>\n<p># \u4f7f\u7528dict()\u51fd\u6570\u521b\u5efa\u7a7a\u5b57\u5178<br \/>\nempty_dict &#061; dict()<\/p>\n<p># \u4f7f\u7528dict()\u51fd\u6570\u521b\u5efa\u5e26\u6709\u952e\u503c\u5bf9\u7684\u5b57\u5178<br \/>\nsample_dict &#061; dict(name&#061;&#034;Alice&#034;, age&#061;25, city&#061;&#034;Beijing&#034;)<\/p>\n<p># \u4f7f\u7528dict()\u51fd\u6570\u4ece\u952e\u503c\u5bf9\u5217\u8868\u521b\u5efa\u5b57\u5178<br \/>\npairs_dict &#061; dict([(&#034;name&#034;, &#034;Bob&#034;), (&#034;age&#034;, 30), (&#034;city&#034;, &#034;Shanghai&#034;)])<\/p>\n<p># \u4f7f\u7528dict()\u51fd\u6570\u4ece\u5173\u952e\u5b57\u53c2\u6570\u521b\u5efa\u5b57\u5178<br \/>\nkwargs_dict &#061; dict(key1&#061;&#034;value1&#034;, key2&#061;&#034;value2&#034;)<\/p>\n<p>print(&#034;\u7a7a\u5b57\u5178:&#034;, empty_dict)<br \/>\nprint(&#034;\u5173\u952e\u5b57\u53c2\u6570\u5b57\u5178:&#034;, sample_dict)<br \/>\nprint(&#034;\u952e\u503c\u5bf9\u5217\u8868\u5b57\u5178:&#034;, pairs_dict)<br \/>\nprint(&#034;\u5173\u952e\u5b57\u53c2\u6570\u5b57\u5178:&#034;, kwargs_dict)<\/p>\n<p>1. dict()\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u7a7a\u5b57\u5178&#xff0c;\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u53c2\u6570\u5f62\u5f0f\u521b\u5efa\u5e26\u952e\u503c\u5bf9\u7684\u5b57\u5178\u3002<br \/>\n2. \u652f\u6301\u5173\u952e\u5b57\u53c2\u6570\u3001\u952e\u503c\u5bf9\u5217\u8868\u7b49\u591a\u79cd\u521b\u5efa\u65b9\u5f0f\u3002<br \/>\n3. \u4e0e\u5927\u62ec\u53f7{}\u8bed\u6cd5\u76f8\u6bd4&#xff0c;dict()\u51fd\u6570\u63d0\u4f9b\u4e86\u66f4\u591a\u521b\u5efa\u5b57\u5178\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<h2 style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u4e09\u3001\u8bbf\u95ee\u5b57\u5178\u7684\u503c<\/span><\/h2>\n<h3>1.\u57fa\u672c\u8bbf\u95ee<\/h3>\n<p>\u8fd9\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5&#xff0c;\u901a\u8fc7\u952e\u6765\u8bbf\u95ee\u5bf9\u5e94\u7684\u503c<\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nperson &#061; {<br \/>\n    &#034;name&#034;: &#034;\u4e54\u5cf0&#034;,<br \/>\n    &#034;age&#034;: 25,<br \/>\n    &#034;city&#034;: &#034;\u5927\u5b8b&#034;<br \/>\n}<\/p>\n<p># \u8bbf\u95ee\u503c<br \/>\nname &#061; person[&#034;name&#034;]<br \/>\nage &#061; person[&#034;age&#034;]<br \/>\nprint(f&#034;\u59d3\u540d: {name}, \u5e74\u9f84: {age}&#034;)  # \u8f93\u51fa&#xff1a;\u59d3\u540d: \u4e54\u5cf0, \u5e74\u9f84: 25<\/p>\n<h3>2.\u4f7f\u7528get()\u65b9\u6cd5\u8bbf\u95ee\u503c<\/h3>\n<p>get()\u65b9\u6cd5\u662f\u8bbf\u95ee\u5b57\u5178\u503c\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f&#xff0c;\u5b83\u6bd4\u65b9\u62ec\u53f7\u8bbf\u95ee<span style=\"color:#fe2c24\">\u66f4\u5b89\u5168<\/span><\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nstudent &#061; {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;grade&#034;: &#034;\u5927\u4e8c&#034;,<br \/>\n    &#034;major&#034;: &#034;\u8ba1\u7b97\u673a\u79d1\u5b66&#034;<br \/>\n}<\/p>\n<p># \u4f7f\u7528get()\u65b9\u6cd5\u8bbf\u95ee\u503c<br \/>\nname &#061; student.get(&#034;name&#034;)<br \/>\nmajor &#061; student.get(&#034;major&#034;)<\/p>\n<p># \u5982\u679c\u952e\u4e0d\u5b58\u5728&#xff0c;get()\u8fd4\u56deNone&#xff08;\u6216\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c&#xff09;<br \/>\nphone &#061; student.get(&#034;phone&#034;, &#034;\u672a\u63d0\u4f9b&#034;)<\/p>\n<p>print(f&#034;\u59d3\u540d: {name}, \u4e13\u4e1a: {major}, \u7535\u8bdd: {phone}&#034;)<\/p>\n<p>\u8f93\u51fa&#xff1a;\u59d3\u540d: \u5f20\u4e09, \u4e13\u4e1a: \u8ba1\u7b97\u673a\u79d1\u5b66, \u7535\u8bdd: \u672a\u63d0\u4f9b<\/p>\n<h3>3.\u8bbf\u95ee\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u503c<\/h3>\n<p>\u5f53\u5b57\u5178\u7684\u503c\u4e5f\u662f\u5b57\u5178\u65f6&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u591a\u5c42\u8bbf\u95ee<\/p>\n<p># \u521b\u5efa\u5d4c\u5957\u5b57\u5178<br \/>\ncompany &#061; {<br \/>\n    &#034;name&#034;: &#034;\u79d1\u6280\u516c\u53f8&#034;,<br \/>\n    &#034;address&#034;: {<br \/>\n        &#034;city&#034;: &#034;\u4e0a\u6d77&#034;,<br \/>\n        &#034;district&#034;: &#034;\u6d66\u4e1c\u65b0\u533a&#034;<br \/>\n    },<br \/>\n    &#034;employees&#034;: [<br \/>\n        {&#034;name&#034;: &#034;\u738b\u4e94&#034;, &#034;position&#034;: &#034;\u5de5\u7a0b\u5e08&#034;},<br \/>\n        {&#034;name&#034;: &#034;\u8d75\u516d&#034;, &#034;position&#034;: &#034;\u8bbe\u8ba1\u5e08&#034;}<br \/>\n    ]<br \/>\n}<\/p>\n<p># \u8bbf\u95ee\u5d4c\u5957\u503c<br \/>\ncity &#061; company[&#034;address&#034;][&#034;city&#034;]<br \/>\nfirst_employee &#061; company[&#034;employees&#034;][0][&#034;name&#034;]<\/p>\n<p>print(f&#034;\u516c\u53f8\u6240\u5728\u57ce\u5e02: {city}&#034;)<br \/>\nprint(f&#034;\u7b2c\u4e00\u4e2a\u5458\u5de5: {first_employee}&#034;)<\/p>\n<p># \u8f93\u51fa&#xff1a;\u516c\u53f8\u6240\u5728\u57ce\u5e02: \u4e0a\u6d77<br \/>\n# \u8f93\u51fa&#xff1a;\u7b2c\u4e00\u4e2a\u5458\u5de5: \u738b\u4e94<\/p>\n<h3>4.\u4f7f\u7528for\u5faa\u73af\u904d\u5386\u5b57\u5178\u503c<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nscores &#061; {<br \/>\n    &#034;\u6570\u5b66&#034;: 95,<br \/>\n    &#034;\u82f1\u8bed&#034;: 88,<br \/>\n    &#034;\u8bed\u6587&#034;: 92<br \/>\n}<\/p>\n<p># \u904d\u5386\u6240\u6709\u503c<br \/>\nprint(&#034;\u6240\u6709\u6210\u7ee9:&#034;)<br \/>\nfor score in scores.values():<br \/>\n    print(score)<\/p>\n<p># \u904d\u5386\u952e\u503c\u5bf9<br \/>\nprint(&#034;\\\\n\u6240\u6709\u79d1\u76ee\u548c\u6210\u7ee9:&#034;)<br \/>\nfor subject, score in scores.items():<br \/>\n    print(f&#034;{subject}: {score}&#034;)<\/p>\n<h3>5.\u5b89\u5168\u8bbf\u95ee\u5b57\u5178\u503c\u7684\u65b9\u6cd5<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\ndata &#061; {<br \/>\n    &#034;username&#034;: &#034;user123&#034;,<br \/>\n    &#034;email&#034;: &#034;user&#064;example.com&#034;<br \/>\n}<\/p>\n<p># \u5b89\u5168\u8bbf\u95ee\u65b9\u6cd5<br \/>\ndef safe_get(dictionary, key, default&#061;None):<br \/>\n    return dictionary.get(key, default)<\/p>\n<p># \u4f7f\u7528\u793a\u4f8b<br \/>\nusername &#061; safe_get(data, &#034;username&#034;)<br \/>\nphone &#061; safe_get(data, &#034;phone&#034;, &#034;\u672a\u63d0\u4f9b&#034;)<br \/>\nprint(f&#034;\u7528\u6237\u540d: {username}&#034;)<br \/>\nprint(f&#034;\u7535\u8bdd: {phone}&#034;)<\/p>\n<h3>6.\u4f7f\u7528in\u5173\u952e\u5b57\u68c0\u67e5\u952e\u662f\u5426\u5b58\u5728<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nsettings &#061; {<br \/>\n    &#034;theme&#034;: &#034;dark&#034;,<br \/>\n    &#034;language&#034;: &#034;zh-CN&#034;<br \/>\n}<\/p>\n<p># \u68c0\u67e5\u952e\u662f\u5426\u5b58\u5728<br \/>\nif &#034;theme&#034; in settings:<br \/>\n    print(f&#034;\u4e3b\u9898\u8bbe\u7f6e: {settings[&#039;theme&#039;]}&#034;)<\/p>\n<p>if &#034;notifications&#034; not in settings:<br \/>\n    print(&#034;\u901a\u77e5\u8bbe\u7f6e\u672a\u914d\u7f6e&#034;)<\/p>\n<h3>7.\u5904\u7406\u952e\u4e0d\u5b58\u5728\u7684\u60c5\u51b5<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nconfig &#061; {<br \/>\n    &#034;debug&#034;: True,<br \/>\n    &#034;port&#034;: 8080<br \/>\n}<\/p>\n<p># \u65b9\u6cd51: \u4f7f\u7528try-except<br \/>\ntry:<br \/>\n    value &#061; config[&#034;host&#034;]<br \/>\nexcept KeyError:<br \/>\n    print(&#034;\u4e3b\u673a\u914d\u7f6e\u4e0d\u5b58\u5728&#034;)<\/p>\n<p># \u65b9\u6cd52: \u4f7f\u7528get()\u65b9\u6cd5<br \/>\nhost &#061; config.get(&#034;host&#034;, &#034;localhost&#034;)<br \/>\nprint(f&#034;\u4e3b\u673a\u5730\u5740: {host}&#034;)<\/p>\n<h3>8.\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5b57\u5178\u5143\u7d20<\/h3>\n<p># \u521b\u5efa\u5305\u542b\u5b57\u5178\u7684\u5217\u8868<br \/>\nusers &#061; [<br \/>\n    {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 25},<br \/>\n    {&#034;name&#034;: &#034;\u674e\u56db&#034;, &#034;age&#034;: 30},<br \/>\n    {&#034;name&#034;: &#034;\u738b\u4e94&#034;, &#034;age&#034;: 28}<br \/>\n]<\/p>\n<p># \u8bbf\u95ee\u5217\u8868\u4e2d\u5b57\u5178\u7684\u503c<br \/>\nfirst_user_name &#061; users[0][&#034;name&#034;]<br \/>\nsecond_user_age &#061; users[1][&#034;age&#034;]<br \/>\nprint(f&#034;\u7b2c\u4e00\u4e2a\u7528\u6237: {first_user_name}, \u7b2c\u4e8c\u4e2a\u7528\u6237\u5e74\u9f84: {second_user_age}&#034;)<\/p>\n<h2><span style=\"color:#0d0016\">\u56db\u3001\u4fee\u6539\u5b57\u5178\u4e2d\u7684\u503c<\/span><\/h2>\n<h3>1.\u76f4\u63a5\u8d4b\u503c\u66f4\u65b0<\/h3>\n<p>\u8fd9\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5&#xff0c;\u901a\u8fc7\u952e\u540d\u76f4\u63a5\u7ed9\u503c\u8d4b\u65b0\u503c<\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nstudent &#061; {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;age&#034;: 20,<br \/>\n    &#034;grade&#034;: &#034;\u5927\u4e8c&#034;<br \/>\n}<\/p>\n<p># \u66f4\u65b0\u73b0\u6709\u952e\u7684\u503c<br \/>\nstudent[&#034;age&#034;] &#061; 21<br \/>\nstudent[&#034;grade&#034;] &#061; &#034;\u5927\u4e09&#034;<\/p>\n<p>print(student)  # {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 21, &#039;grade&#039;: &#039;\u5927\u4e09&#039;}<\/p>\n<h3>2.\u4f7f\u7528update()\u65b9\u6cd5<\/h3>\n<p>update()\u65b9\u6cd5\u53ef\u4ee5\u4e00\u6b21\u66f4\u65b0\u591a\u4e2a\u952e\u503c\u5bf9&#xff1a;<\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nproduct &#061; {<br \/>\n    &#034;name&#034;: &#034;\u7b14\u8bb0\u672c\u7535\u8111&#034;,<br \/>\n    &#034;price&#034;: 5000,<br \/>\n    &#034;brand&#034;: &#034;\u8054\u60f3&#034;<br \/>\n}<\/p>\n<p># \u4f7f\u7528update()\u65b9\u6cd5\u66f4\u65b0\u591a\u4e2a\u503c<br \/>\nproduct.update({&#034;price&#034;: 4500, &#034;brand&#034;: &#034;\u534e\u4e3a&#034;})<br \/>\nprint(product)  # {&#039;name&#039;: &#039;\u7b14\u8bb0\u672c\u7535\u8111&#039;, &#039;price&#039;: 4500, &#039;brand&#039;: &#039;\u534e\u4e3a&#039;}<\/p>\n<p># \u4e5f\u53ef\u4ee5\u4f20\u5165\u5173\u952e\u5b57\u53c2\u6570<br \/>\nproduct.update(name&#061;&#034;\u53f0\u5f0f\u7535\u8111&#034;, price&#061;3000)<br \/>\nprint(product)  # {&#039;name&#039;: &#039;\u53f0\u5f0f\u7535\u8111&#039;, &#039;price&#039;: 3000, &#039;brand&#039;: &#039;\u534e\u4e3a&#039;}<\/p>\n<h3>3.\u4f7f\u7528setdefault()\u65b9\u6cd5<\/h3>\n<p>setdefault()\u65b9\u6cd5\u5982\u679c\u952e\u4e0d\u5b58\u5728\u5219\u6dfb\u52a0\u952e\u503c\u5bf9&#xff0c;\u5982\u679c\u5b58\u5728\u5219\u8fd4\u56de\u539f\u503c&#xff1a;<\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nconfig &#061; {<br \/>\n    &#034;theme&#034;: &#034;dark&#034;,<br \/>\n    &#034;language&#034;: &#034;zh-CN&#034;<br \/>\n}<\/p>\n<p># \u66f4\u65b0\u5df2\u5b58\u5728\u7684\u952e<br \/>\nconfig.setdefault(&#034;theme&#034;, &#034;light&#034;)  # \u8fd4\u56de&#034;dark&#034;&#xff0c;\u4e0d\u6539\u53d8\u539f\u503c<br \/>\nprint(config[&#034;theme&#034;])  # &#034;dark&#034;<\/p>\n<p># \u6dfb\u52a0\u65b0\u952e\u503c\u5bf9<br \/>\nconfig.setdefault(&#034;font_size&#034;, 14)  # \u6dfb\u52a0\u65b0\u952e\u503c\u5bf9<br \/>\nprint(config)  # {&#039;theme&#039;: &#039;dark&#039;, &#039;language&#039;: &#039;zh-CN&#039;, &#039;font_size&#039;: 14}<\/p>\n<p>4.\u66f4\u65b0\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u503c<\/p>\n<p>company &#061; {<br \/>\n    &#034;name&#034;: &#034;\u79d1\u6280\u516c\u53f8&#034;,<br \/>\n    &#034;address&#034;: {<br \/>\n        &#034;city&#034;: &#034;\u4e0a\u6d77&#034;,<br \/>\n        &#034;district&#034;: &#034;\u6d66\u4e1c\u65b0\u533a&#034;<br \/>\n    }<br \/>\n}<\/p>\n<p># \u66f4\u65b0\u5d4c\u5957\u5b57\u5178\u4e2d\u7684\u503c<br \/>\ncompany[&#034;address&#034;][&#034;city&#034;] &#061; &#034;\u6df1\u5733&#034;<br \/>\ncompany[&#034;address&#034;][&#034;district&#034;] &#061; &#034;\u5357\u5c71\u533a&#034;<\/p>\n<p>print(company)  # {&#039;name&#039;: &#039;\u79d1\u6280\u516c\u53f8&#039;, &#039;address&#039;: {&#039;city&#039;: &#039;\u6df1\u5733&#039;, &#039;district&#039;: &#039;\u5357\u5c71\u533a&#039;}}<\/p>\n<h3>5.\u6761\u4ef6\u6027\u66f4\u65b0<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nscores &#061; {<br \/>\n    &#034;\u6570\u5b66&#034;: 85,<br \/>\n    &#034;\u82f1\u8bed&#034;: 92,<br \/>\n    &#034;\u8bed\u6587&#034;: 78<br \/>\n}<\/p>\n<p># \u53ea\u6709\u5f53\u5206\u6570\u4f4e\u4e8e\u67d0\u4e2a\u503c\u65f6\u624d\u66f4\u65b0<br \/>\nif scores[&#034;\u6570\u5b66&#034;] &lt; 90:<br \/>\n    scores[&#034;\u6570\u5b66&#034;] &#061; 90<\/p>\n<p>print(scores)  # {&#039;\u6570\u5b66&#039;: 90, &#039;\u82f1\u8bed&#039;: 92, &#039;\u8bed\u6587&#039;: 78}<\/p>\n<h3>6.\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u66f4\u65b0<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nnumbers &#061; {&#034;a&#034;: 1, &#034;b&#034;: 2, &#034;c&#034;: 3}<\/p>\n<p># \u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u66f4\u65b0\u503c&#xff08;\u5c06\u6240\u6709\u503c\u4e58\u4ee52&#xff09;<br \/>\nupdated_numbers &#061; {key: value * 2 for key, value in numbers.items()}<br \/>\nprint(updated_numbers)  # {&#039;a&#039;: 2, &#039;b&#039;: 4, &#039;c&#039;: 6}<\/p>\n<h3>7.\u4f7f\u7528for\u5faa\u73af\u6279\u91cf\u66f4\u65b0<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nprices &#061; {&#034;\u82f9\u679c&#034;: 5, &#034;\u9999\u8549&#034;: 3, &#034;\u6a59\u5b50&#034;: 4}<\/p>\n<p># \u6279\u91cf\u66f4\u65b0\u4ef7\u683c&#xff08;\u589e\u52a010%&#xff09;<br \/>\nfor fruit in prices:<br \/>\n    prices[fruit] &#061; round(prices[fruit] * 1.1, 2)<\/p>\n<p>print(prices)  # {&#039;\u82f9\u679c&#039;: 5.5, &#039;\u9999\u8549&#039;: 3.3, &#039;\u6a59\u5b50&#039;: 4.4}<\/p>\n<h3>8.\u5408\u5e76\u5b57\u5178\u66f4\u65b0<\/h3>\n<p># \u521b\u5efa\u4e24\u4e2a\u5b57\u5178<br \/>\ndict1 &#061; {&#034;a&#034;: 1, &#034;b&#034;: 2}<br \/>\ndict2 &#061; {&#034;b&#034;: 20, &#034;c&#034;: 30}<\/p>\n<p># \u5408\u5e76\u66f4\u65b0dict1<br \/>\ndict1.update(dict2)<br \/>\nprint(dict1)  # {&#039;a&#039;: 1, &#039;b&#039;: 20, &#039;c&#039;: 30}<\/p>\n<p>\u8fd9\u4e9b\u65b9\u6cd5\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u66f4\u65b0\u5b57\u5178\u4e2d\u7684\u503c&#xff0c;\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u76f4\u63a5\u8d4b\u503c\u9002\u5408\u5355\u4e2a\u503c\u66f4\u65b0&#xff0c;update()\u65b9\u6cd5\u9002\u5408\u6279\u91cf\u66f4\u65b0&#xff0c;\u800c\u5d4c\u5957\u5b57\u5178\u7684\u66f4\u65b0\u9700\u8981\u591a\u5c42\u8bbf\u95ee\u3002<\/p>\n<h2>\u4e94\u3001\u5220\u9664\u5b57\u5178\u5143\u7d20<\/h2>\n<h3>1.\u4f7f\u7528 del \u8bed\u53e5\u5220\u9664\u6307\u5b9a\u952e\u503c\u5bf9<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nstudent &#061; {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;age&#034;: 25,<br \/>\n    &#034;grade&#034;: &#034;\u5927\u4e8c&#034;<br \/>\n}<\/p>\n<p># \u5220\u9664\u6307\u5b9a\u952e\u503c\u5bf9<br \/>\ndel student[&#034;grade&#034;]<br \/>\nprint(student)  # {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 25}<\/p>\n<h3>2.\u4f7f\u7528 pop() \u65b9\u6cd5\u5220\u9664\u5e76\u8fd4\u56de\u503c<\/h3>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nstudent &#061; {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;age&#034;: 25,<br \/>\n    &#034;grade&#034;: &#034;\u5927\u4e8c&#034;<br \/>\n}<\/p>\n<p># \u5220\u9664\u5e76\u8fd4\u56de\u503c<br \/>\ngrade &#061; student.pop(&#034;grade&#034;)<br \/>\nprint(f&#034;\u5220\u9664\u7684\u503c: {grade}&#034;)  # \u5220\u9664\u7684\u503c: \u5927\u4e8c<br \/>\nprint(student)  # {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 25}<\/p>\n<p># \u952e\u4e0d\u5b58\u5728\u65f6\u8bbe\u7f6e\u9ed8\u8ba4\u503c<br \/>\nphone &#061; student.pop(&#034;phone&#034;, &#034;\u672a\u63d0\u4f9b&#034;)<br \/>\nprint(f&#034;\u7535\u8bdd: {phone}&#034;)  # \u7535\u8bdd: \u672a\u63d0\u4f9b<\/p>\n<h3>3.\u00a0\u4f7f\u7528 popitem() \u65b9\u6cd5\u5220\u9664\u6700\u540e\u4e00\u4e2a\u952e\u503c\u5bf9<\/h3>\n<p>popitem() \u65b9\u6cd5\u5220\u9664\u5e76\u8fd4\u56de\u5b57\u5178\u4e2d\u7684\u4efb\u610f\u952e\u503c\u5bf9&#xff08;\u5728 Python 3.7&#043; \u4e2d\u4fdd\u8bc1\u5220\u9664\u6700\u540e\u4e00\u4e2a&#xff09;&#xff1a;<\/p>\n<p># \u521b\u5efa\u5b57\u5178<br \/>\nstudent &#061; {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;age&#034;: 25,<br \/>\n    &#034;grade&#034;: &#034;\u5927\u4e8c&#034;<br \/>\n}<\/p>\n<p># \u5220\u9664\u6700\u540e\u4e00\u4e2a\u952e\u503c\u5bf9<br \/>\nlast_item &#061; student.popitem()<br \/>\nprint(f&#034;\u5220\u9664\u7684\u952e\u503c\u5bf9: {last_item}&#034;)  # \u5220\u9664\u7684\u952e\u503c\u5bf9: (&#039;grade&#039;, &#039;\u5927\u4e8c&#039;)<br \/>\nprint(student)  # {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 25}<\/p>\n<h3>4.\u4f7f\u7528 clear() \u65b9\u6cd5\u6e05\u7a7a\u6240\u6709\u5143\u7d20<\/h3>\n<p>\u4f7f\u7528\u00a0clear()\u00a0\u65b9\u6cd5\u53ef\u4ee5\u6e05\u7a7a\u5b57\u5178\u4e2d\u7684\u6240\u6709\u5143\u7d20&#xff0c;<span style=\"color:#fe2c24\">\u5b57\u5178\u672c\u8eab\u4ecd\u7136\u5b58\u5728&#xff0c;\u614e\u7528<\/span>\u3002<\/p>\n<p># \u793a\u4f8b\u5b57\u5178<br \/>\nstudent &#061; {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 20, &#039;score&#039;: 85, &#039;city&#039;: &#039;\u5317\u4eac&#039;}<\/p>\n<p>student.clear()<br \/>\nprint(&#034;\u4f7f\u7528 clear \u6e05\u7a7a\u5b57\u5178\u540e:&#034;, student)<\/p>\n<p>5.\u5220\u9664\u6574\u4e2a\u5b57\u5178<\/p>\n<p>\u4f7f\u7528\u00a0del\u00a0\u8bed\u53e5\u53ef\u4ee5\u5220\u9664\u6574\u4e2a\u5b57\u5178&#xff0c;\u5220\u9664\u540e<span style=\"color:#fe2c24\">\u5b57\u5178\u4e0d\u518d\u5b58\u5728&#xff0c;\u614e\u7528<\/span>\u3002<\/p>\n<p># \u793a\u4f8b\u5b57\u5178<br \/>\nstudent &#061; {&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 20, &#039;score&#039;: 85, &#039;city&#039;: &#039;\u5317\u4eac&#039;}<\/p>\n<p>del student  # \u5220\u9664\u5b57\u5178<\/p>\n<p># \u6b64\u65f6\u8bbf\u95ee tinydict \u4f1a\u629b\u51fa NameError \u9519\u8bef<br \/>\nprint(student)<\/p>\n<h2>\u516d\u3001\u7279\u5f81<\/h2>\n<li>\u952e\u503c\u5bf9\u5b58\u50a8\u200c&#xff1a;\u5b57\u5178\u4ee5\u952e\u503c\u5bf9&#xff08;key-value pairs&#xff09;\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e&#xff0c;\u6bcf\u4e2a\u952e&#xff08;key&#xff09;\u90fd\u552f\u4e00\u5bf9\u5e94\u4e00\u4e2a\u503c&#xff08;value&#xff09;\u3002<\/li>\n<li>\u952e\u7684\u552f\u4e00\u6027\u200c&#xff1a;\u5b57\u5178\u4e2d\u7684\u952e\u5fc5\u987b\u662f\u552f\u4e00\u7684&#xff0c;\u5982\u679c\u91cd\u590d\u5b9a\u4e49\u540c\u4e00\u4e2a\u952e&#xff0c;\u540e\u9762\u7684\u503c\u4f1a\u8986\u76d6\u524d\u9762\u7684\u503c\u3002<\/li>\n<li>\u952e\u7684\u4e0d\u53ef\u53d8\u6027\u200c&#xff1a;\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff0c;\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u6216\u5143\u7ec4\u7b49&#xff0c;\u800c\u503c\u53ef\u4ee5\u662f\u4efb\u610f\u7c7b\u578b\u3002<\/li>\n<li>\u53ef\u53d8\u6027\u200c&#xff1a;\u5b57\u5178\u662f\u53ef\u53d8\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u968f\u65f6\u6dfb\u52a0\u3001\u4fee\u6539\u6216\u5220\u9664\u952e\u503c\u5bf9\u3002<\/li>\n<li>\u65e0\u5e8f\u6027\u200c&#xff1a;\u5728 Python 3.7 \u53ca\u4ee5\u540e\u7248\u672c\u4e2d&#xff0c;\u5b57\u5178\u4fdd\u6301\u63d2\u5165\u987a\u5e8f&#xff0c;\u4f46\u5728\u8f83\u65e9\u7248\u672c\u4e2d&#xff0c;\u5b57\u5178\u662f\u65e0\u5e8f\u7684\u3002<\/li>\n<li>\u9ad8\u6548\u67e5\u627e\u200c&#xff1a;\u901a\u8fc7\u952e\u8bbf\u95ee\u503c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(1)&#xff0c;\u56e0\u6b64\u5b57\u5178\u5728\u67e5\u627e\u64cd\u4f5c\u4e0a\u975e\u5e38\u9ad8\u6548\u3002<\/li>\n<li>\u652f\u6301\u591a\u79cd\u64cd\u4f5c\u200c&#xff1a;\u5305\u62ec\u952e\u503c\u5bf9\u7684\u589e\u5220\u6539\u67e5\u3001\u904d\u5386\u3001\u5408\u5e76\u7b49\u64cd\u4f5c\u3002<\/li>\n<p>\u8fd9\u4e9b\u7279\u6027\u4f7f\u5f97 Python \u5b57\u5178\u5728\u5904\u7406\u9700\u8981\u5feb\u901f\u67e5\u627e\u548c\u52a8\u6001\u66f4\u65b0\u7684\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h2>\u4e03\u3001\u5b57\u5178\u5e38\u7528\u5185\u7f6e\u51fd\u6570<\/h2>\n<h3>1.len()\u00a0\u51fd\u6570<\/h3>\n<p>\u7528\u4e8e\u83b7\u53d6\u5b57\u5178\u4e2d\u952e\u503c\u5bf9\u7684\u6570\u91cf<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25, &#034;city&#034;: &#034;New York&#034;}<br \/>\nprint(len(my_dict))  # \u8f93\u51fa: 3<\/p>\n<h3>2.type()\u00a0\u51fd\u6570<\/h3>\n<p>\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u7684\u7c7b\u578b<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25, &#034;city&#034;: &#034;New York&#034;}<br \/>\nprint(type(my_dict))  # \u8f93\u51fa: &lt;class &#039;dict&#039;&gt;<\/p>\n<h3>3.str()\u00a0\u51fd\u6570<\/h3>\n<p>\u5c06\u5b57\u5178\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u8868\u793a\u5f62\u5f0f<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25, &#034;city&#034;: &#034;New York&#034;}<br \/>\nprint(str(my_dict))  # \u8f93\u51fa: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 25, &#039;city&#039;: &#039;New York&#039;}<\/p>\n<h2>\u516b\u3001\u5b57\u5178\u5e38\u7528\u5185\u7f6e\u65b9\u6cd5<\/h2>\n<h3>1.get(key[, default])\u00a0\u65b9\u6cd5<\/h3>\n<p>\u8fd4\u56de\u6307\u5b9a\u952e\u5bf9\u5e94\u7684\u503c&#xff0c;\u5982\u679c\u952e\u4e0d\u5b58\u5728&#xff0c;\u5219\u8fd4\u56de\u00a0default&#xff08;\u5982\u679c\u672a\u6307\u5b9a\u00a0default&#xff0c;\u5219\u8fd4\u56de\u00a0None&#xff09;<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25, &#034;city&#034;: &#034;New York&#034;}<br \/>\nprint(my_dict.get(&#034;name&#034;))  # \u8f93\u51fa: Alice<br \/>\nprint(my_dict.get(&#034;job&#034;, &#034;Not Found&#034;))  # \u8f93\u51fa: Not Found<\/p>\n<h3>2.setdefault(key[, default])\u00a0\u65b9\u6cd5<\/h3>\n<p>\u5982\u679c\u952e\u5b58\u5728\u4e8e\u5b57\u5178\u4e2d&#xff0c;\u5219\u8fd4\u56de\u5176\u5bf9\u5e94\u7684\u503c&#xff1b;\u5982\u679c\u952e\u4e0d\u5b58\u5728&#xff0c;\u5219\u5c06\u952e\u6dfb\u52a0\u5230\u5b57\u5178\u4e2d&#xff0c;\u5e76\u5c06\u5176\u503c\u8bbe\u7f6e\u4e3a\u00a0default&#xff08;\u5982\u679c\u672a\u6307\u5b9a\u00a0default&#xff0c;\u5219\u8bbe\u7f6e\u4e3a\u00a0None&#xff09;<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\ngender &#061; my_dict.setdefault(&#034;gender&#034;, &#034;Unknown&#034;)<br \/>\nprint(gender)  # \u8f93\u51fa: Unknown<br \/>\nprint(my_dict)  # \u8f93\u51fa: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 25, &#039;gender&#039;: &#039;Unknown&#039;}<\/p>\n<h3>3.update([other])\u00a0\u65b9\u6cd5<\/h3>\n<p>\u7528\u4e8e\u5c06\u4e00\u4e2a\u5b57\u5178\u7684\u952e\u503c\u5bf9\u66f4\u65b0\u5230\u53e6\u4e00\u4e2a\u5b57\u5178\u4e2d\u3002\u5b83\u53ef\u4ee5\u63a5\u53d7\u53e6\u4e00\u4e2a\u5b57\u5178\u6216\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570<\/p>\n<p>dict1 &#061; {&#034;key1&#034;: &#034;value1&#034;, &#034;key2&#034;: &#034;value2&#034;}<br \/>\ndict1.update({&#034;key1&#034;: &#034;new_value&#034;})  # \u952e\u5b58\u5728\u65f6\u66f4\u65b0\u503c<br \/>\nprint(dict1)  # \u8f93\u51fa: {&#039;key1&#039;: &#039;new_value&#039;, &#039;key2&#039;: &#039;value2&#039;}<\/p>\n<p>dict1.update({&#034;key3&#034;: &#034;value3&#034;})  # \u952e\u4e0d\u5b58\u5728\u65f6\u63d2\u5165\u65b0\u952e\u503c\u5bf9<br \/>\nprint(dict1)  # \u8f93\u51fa: {&#039;key1&#039;: &#039;new_value&#039;, &#039;key2&#039;: &#039;value2&#039;, &#039;key3&#039;: &#039;value3&#039;}<\/p>\n<h3>4.clear()\u00a0\u65b9\u6cd5<\/h3>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\nmy_dict.clear()<br \/>\nprint(my_dict)  # \u8f93\u51fa: {}<\/p>\n<p>5.copy()\u00a0\u65b9\u6cd5<\/p>\n<p>\u8fd4\u56de\u5b57\u5178\u7684\u4e00\u4e2a\u6d45\u62f7\u8d1d<\/p>\n<p>original_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\nnew_dict &#061; original_dict.copy()<br \/>\nprint(new_dict)  # \u8f93\u51fa: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 25}<\/p>\n<p>6.fromkeys()\u00a0\u65b9\u6cd5<\/p>\n<p>\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u65b0\u5b57\u5178&#xff0c;\u4ee5\u5e8f\u5217\u4e2d\u7684\u5143\u7d20\u4f5c\u4e3a\u952e&#xff0c;value\u00a0\u4f5c\u4e3a\u6240\u6709\u952e\u5bf9\u5e94\u7684\u521d\u59cb\u503c<\/p>\n<p>keys &#061; [&#034;name&#034;, &#034;age&#034;, &#034;city&#034;]<br \/>\ndefault_value &#061; &#034;Unknown&#034;<br \/>\nnew_dict &#061; dict.fromkeys(keys, default_value)<br \/>\nprint(new_dict)  # \u8f93\u51fa: {&#039;name&#039;: &#039;Unknown&#039;, &#039;age&#039;: &#039;Unknown&#039;, &#039;city&#039;: &#039;Unknown&#039;}<\/p>\n<p>7.items()\u00a0\u65b9\u6cd5<\/p>\n<p>\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u53ef\u904d\u5386\u7684&#xff08;\u952e&#xff0c;\u503c&#xff09;\u5143\u7ec4\u6570\u7ec4<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\nprint(my_dict.items())  # \u8f93\u51fa: dict_items([(&#039;name&#039;, &#039;Alice&#039;), (&#039;age&#039;, 25)])<\/p>\n<p>8.keys()\u00a0\u65b9\u6cd5<\/p>\n<p>\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u5b57\u5178\u4e2d\u6240\u6709\u7684\u952e<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\nprint(my_dict.keys())  # \u8f93\u51fa: dict_keys([&#039;name&#039;, &#039;age&#039;])<\/p>\n<p>9.values()\u00a0\u65b9\u6cd5<\/p>\n<p>\u4ee5\u5217\u8868\u5f62\u5f0f\u8fd4\u56de\u5b57\u5178\u4e2d\u6240\u6709\u7684\u503c<\/p>\n<p>my_dict &#061; {&#034;name&#034;: &#034;Alice&#034;, &#034;age&#034;: 25}<br \/>\nprint(my_dict.values())  # \u8f93\u51fa: dict_values([&#039;Alice&#039;, 25])<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6539\u53d8\u4ece\u4e0d\u662f\u4e00\u8e74\u800c\u5c31&#xff0c;\u800c\u662f\u65e5\u79ef\u6708\u7d2f\u7684\u4fee\u6b63\u3002\u4eca\u5929\u7684\u81ea\u5f8b&#xff0c;\u662f\u660e\u5929\u7684\u81ea\u7531\u3002\u5b66\u4e60\u6253\u5361\u7b2c\u5341\u4e09\u5929\u5728 Python \u4e2d&#xff0c;\u5b57\u5178&#xff08;Dictionary&#xff09;\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u53ef\u53d8\u5bb9\u5668\u6a21\u578b&#xff0c;\u5b83\u80fd\u591f\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u5728\u6570\u636e\u5904\u7406\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u573a\u666f\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4e00\u3001\u5b57\u5178\u7684\u57fa\u672c\u6982\u5ff5\u5b57\u5178\u7531\u4e00\u7cfb\u5217\u952e\u503c\u5bf9(key:value&#xff09;\u7ec4\u6210&#xff0c;\u5176\u57fa\u672c\u683c\u5f0f\u5982\u4e0b&#xff1a;dic\u00a0 {key1: va<\/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":[7203,81,2884,371,190],"topic":[],"class_list":{"0":"post-68227","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-dictionary","8":"tag-python","10":"tag-371","11":"tag-190"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \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\/68227.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6539\u53d8\u4ece\u4e0d\u662f\u4e00\u8e74\u800c\u5c31&#xff0c;\u800c\u662f\u65e5\u79ef\u6708\u7d2f\u7684\u4fee\u6b63\u3002\u4eca\u5929\u7684\u81ea\u5f8b&#xff0c;\u662f\u660e\u5929\u7684\u81ea\u7531\u3002\u5b66\u4e60\u6253\u5361\u7b2c\u5341\u4e09\u5929\u5728 Python \u4e2d&#xff0c;\u5b57\u5178&#xff08;Dictionary&#xff09;\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u53ef\u53d8\u5bb9\u5668\u6a21\u578b&#xff0c;\u5b83\u80fd\u591f\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u5728\u6570\u636e\u5904\u7406\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u573a\u666f\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4e00\u3001\u5b57\u5178\u7684\u57fa\u672c\u6982\u5ff5\u5b57\u5178\u7531\u4e00\u7cfb\u5217\u952e\u503c\u5bf9(key:value&#xff09;\u7ec4\u6210&#xff0c;\u5176\u57fa\u672c\u683c\u5f0f\u5982\u4e0b&#xff1a;dic\u00a0 {key1: va\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/68227.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-29T13:57:27+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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68227.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/68227.html\",\"name\":\"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-29T13:57:27+00:00\",\"dateModified\":\"2026-01-29T13:57:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/68227.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/68227.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68227.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3\"}]},{\"@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":"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \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\/68227.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6539\u53d8\u4ece\u4e0d\u662f\u4e00\u8e74\u800c\u5c31&#xff0c;\u800c\u662f\u65e5\u79ef\u6708\u7d2f\u7684\u4fee\u6b63\u3002\u4eca\u5929\u7684\u81ea\u5f8b&#xff0c;\u662f\u660e\u5929\u7684\u81ea\u7531\u3002\u5b66\u4e60\u6253\u5361\u7b2c\u5341\u4e09\u5929\u5728 Python \u4e2d&#xff0c;\u5b57\u5178&#xff08;Dictionary&#xff09;\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u53ef\u53d8\u5bb9\u5668\u6a21\u578b&#xff0c;\u5b83\u80fd\u591f\u5b58\u50a8\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u5728\u6570\u636e\u5904\u7406\u3001\u914d\u7f6e\u7ba1\u7406\u7b49\u573a\u666f\u4e2d\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4e00\u3001\u5b57\u5178\u7684\u57fa\u672c\u6982\u5ff5\u5b57\u5178\u7531\u4e00\u7cfb\u5217\u952e\u503c\u5bf9(key:value&#xff09;\u7ec4\u6210&#xff0c;\u5176\u57fa\u672c\u683c\u5f0f\u5982\u4e0b&#xff1a;dic\u00a0 {key1: va","og_url":"https:\/\/www.wsisp.com\/helps\/68227.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-29T13:57:27+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/68227.html","url":"https:\/\/www.wsisp.com\/helps\/68227.html","name":"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-29T13:57:27+00:00","dateModified":"2026-01-29T13:57:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/68227.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/68227.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/68227.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u5b66\u4e60\u4e4b\u8def-\u5b57\u5178(Dictionary)\u5b66\u4e60\u8be6\u89e3"}]},{"@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\/68227","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=68227"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/68227\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=68227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=68227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=68227"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=68227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}