{"id":277,"date":"2023-10-27T09:59:01","date_gmt":"2023-10-27T01:59:01","guid":{"rendered":"http:\/\/ai.gitpp.com\/?p=277"},"modified":"2023-10-30T19:16:57","modified_gmt":"2023-10-30T11:16:57","slug":"%e3%80%8apython%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%e3%80%8b5-%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/27\/%e3%80%8apython%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%e3%80%8b5-%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84\/","title":{"rendered":"\u300aPython\u5165\u95e8\u6559\u7a0b\u300b5. \u6570\u636e\u7ed3\u6784"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5f00\u80c3\u83dc<\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/2-%e4%bd%bf%e7%94%a8-python-%e8%a7%a3%e9%87%8a%e5%99%a8\/\">\u4f7f\u7528 Python \u89e3\u91ca\u5668<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/3-%e9%9d%9e%e6%ad%a3%e5%bc%8f%e4%bb%8b%e7%bb%8dpython\/\">\u975e\u6b63\u5f0f\u4ecb\u7ecdPython<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/4-%e6%b7%b1%e5%85%a5%e6%b5%81%e7%a8%8b%e6%8e%a7%e5%88%b6\/\">\u6df1\u5165\u6d41\u7a0b\u63a7\u5236<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/5-%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84\/\">\u6570\u636e\u7ed3\u6784<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/6-%e6%a8%a1%e5%9d%97\/\">\u6a21\u5757<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/7-%e8%be%93%e5%85%a5%e5%92%8c%e8%be%93%e5%87%ba\/\">\u8f93\u5165\u548c\u8f93\u51fa<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/8-%e9%94%99%e8%af%af%e5%92%8c%e5%bc%82%e5%b8%b8\/\">\u9519\u8bef\u548c\u5f02\u5e38<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/9-%e7%b1%bb\/\">\u7c7b<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/10-%e6%a0%87%e5%87%86%e5%ba%93%e7%9a%84%e7%ae%80%e6%98%8e%e4%bb%8b%e7%bb%8d\/\">\u6807\u51c6\u5e93\u7684\u7b80\u660e\u4ecb\u7ecd<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/11-%e6%a0%87%e5%87%86%e5%ba%93%e7%9a%84%e7%ae%80%e6%98%8e%e4%bb%8b%e7%bb%8d%ef%bc%88%e7%ac%ac%e4%ba%8c%e9%83%a8%e5%88%86%ef%bc%89\/\">\u6807\u51c6\u5e93\u7684\u7b80\u660e\u4ecb\u7ecd\uff08\u7b2c\u4e8c\u90e8\u5206\uff09<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/12-%e7%8e%b0%e5%9c%a8%e5%b9%b2%e4%bb%80%e4%b9%88\/\">\u73b0\u5728\u5e72\u4ec0\u4e48?<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/13-%e4%ba%a4%e4%ba%92%e5%bc%8f%e8%be%93%e5%85%a5%e7%bc%96%e8%be%91%e5%8f%8a%e5%8e%86%e5%8f%b2%e6%9b%bf%e4%bb%a3\/\">\u4ea4\u4e92\u5f0f\u8f93\u5165\u7f16\u8f91\u53ca\u5386\u53f2\u66ff\u4ee3<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/14-%e6%b5%ae%e7%82%b9%e7%ae%97%e6%9c%af-%e9%97%ae%e9%a2%98%e5%92%8c%e9%99%90%e5%88%b6\/\">\u6d6e\u70b9\u7b97\u672f: \u95ee\u9898\u548c\u9650\u5236<\/a><\/li>\n<\/ol>\n\n\n\n<p><em># \u5269\u4f59\u7684\u961f\u5217, \u5b83\u6309\u7167\u8fdb\u5165\u7684\u987a\u5e8f\u6392\u5217<\/em>&nbsp;deque([\u2018Michael\u2019, \u2018Terry\u2019, \u2018Graham\u2019])<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.1.3. \u5217\u8868\u63a8\u5bfc\u5f0f<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-listcomps\"><\/a><\/h3>\n\n\n\n<p>\u5217\u8868\u63a8\u5bfc\u5f0f\u63d0\u4f9b\u4e86\u4ece\u5e8f\u5217\u4e2d\u521b\u5efa\u5217\u8868\u7684\u7b80\u4fbf\u9014\u5f84. \u901a\u5e38\u7a0b\u5e8f\u4f1a\u5bf9\u5e8f\u5217\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u505a\u4e9b\u64cd\u4f5c,\u5e76\u4ee5\u5176\u7ed3\u679c\u4f5c\u4e3a\u65b0\u5217\u8868\u7684\u5143\u7d20, \u6216\u8005\u6839\u636e\u6307\u5b9a\u7684\u6761\u4ef6\u6765\u521b\u5efa\u5b50\u5e8f\u5217.<\/p>\n\n\n\n<p>\u800c\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u7ed3\u6784\u662f, \u5728\u4e00\u4e2a\u65b9\u62ec\u53f7\u91cc, \u9996\u5148\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f, \u968f\u540e\u662f\u4e00\u4e2a&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#for\"><code>for<\/code><\/a>&nbsp;\u5b50\u53e5, \u7136\u540e\u662f\u96f6\u4e2a\u6216\u66f4\u591a\u7684&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#for\"><code>for<\/code><\/a>&nbsp;\u6216&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#if\"><code>if<\/code><\/a>&nbsp;\u5b50\u53e5. \u7ed3\u679c\u5c06\u662f\u901a\u8fc7\u8ba1\u7b97&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#for\"><code>for<\/code><\/a>&nbsp;\u548c&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#if\"><code>if<\/code><\/a>&nbsp;\u5b50\u53e5\u6765\u83b7\u5f97\u7684\u4e00\u4e2a\u5217\u8868. \u5982\u679c\u8981\u4f7f\u8868\u8fbe\u5f0f\u63a8\u5bfc\u5f0f\u51fa\u5143\u7ec4, \u5c31\u5fc5\u987b\u7528\u5706\u62ec\u53f7.<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u5c06\u4e00\u4e2a\u6570\u5b57\u5217\u8868\u6bcf\u4e2a\u5143\u7d20\u7ffb\u4e09\u500d\u4ece\u800c\u751f\u6210\u4e00\u4e2a\u65b0\u5217\u8868:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>vec = [2, 4, 6]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[3*x\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[6, 12, 18]<\/p>\n\n\n\n<p>\u73b0\u5728\u52a0\u70b9\u513f\u5c0f\u82b1\u6837:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[[x, x**2]\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[[2, 4], [4, 16], [6, 36]]<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u5bf9\u5e8f\u5217\u91cc\u6bcf\u4e00\u9879\u9010\u4e2a\u8c03\u7528\u67d0\u65b9\u6cd5:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>freshfruit = [\u2018 banana\u2019, \u2018 loganberry \u2018, \u2018passion fruit \u2018]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[weapon.strip()\u00a0<strong>for<\/strong>\u00a0weapon\u00a0<strong>in<\/strong>\u00a0freshfruit] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[\u2018banana\u2019, \u2018loganberry\u2019, \u2018passion fruit\u2019]<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/compound_stmts.html#if\"><code>if<\/code><\/a>\u00a0\u5b50\u53e5\u6765\u8fdb\u884c\u8fc7\u6ee4:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[3*x\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec\u00a0<strong>if<\/strong>\u00a0x > 3] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[12, 18]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[3*x\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec\u00a0<strong>if<\/strong>\u00a0x &lt; 2] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[]<\/p>\n\n\n\n<p>\u5143\u7ec4\u7ecf\u5e38\u80fd\u4e0d\u7528\u5706\u62ec\u53f7\u800c\u521b\u5efa, \u4f46\u8fd9\u91cc\u4e0d\u884c:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[x, x**2\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec]\u00a0<em># error \u2013 parens required for tuples<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">File \u201c&lt;stdin>\u201d, line 1, in ? <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[x, x**2 for x in vec] ^<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> SyntaxError: invalid syntax\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[(x, x**2)\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[(2, 4), (4, 16), (6, 36)]<\/p>\n\n\n\n<p>\u8fd9\u91cc\u662f\u4e00\u4e9b\u5faa\u73af\u7684\u5d4c\u5957\u548c\u5176\u5b83\u6280\u5de7\u7684\u6f14\u793a:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>vec1 = [2, 4, 6]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>vec2 = [4, 3, -9]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[x*y\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec1\u00a0<strong>for<\/strong>\u00a0y\u00a0<strong>in<\/strong>\u00a0vec2]<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [8, 6, -18, 16, 12, -36, 24, 18, -54]<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>[x+y\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0vec1\u00a0<strong>for<\/strong>\u00a0y\u00a0<strong>in<\/strong>\u00a0vec2] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[6, 5, -7, 8, 7, -5, 10, 9, -3]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[vec1[i]*vec2[i]\u00a0<strong>for<\/strong>\u00a0i\u00a0<strong>in<\/strong>\u00a0range(len(vec1))]<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [8, 12, -54]<\/p>\n\n\n\n<p>\u5217\u8868\u63a8\u5bfc\u5f0f\u53ef\u4f7f\u7528\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u548c\u5d4c\u5957\u7684\u51fd\u5f0f:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>[str(round(355\/113, i))\u00a0<strong>for<\/strong>\u00a0i\u00a0<strong>in<\/strong>\u00a0range(1, 6)] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[\u20183.1\u2019, \u20183.14\u2019, \u20183.142\u2019, \u20183.1416\u2019, \u20183.14159\u2019]<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.1.4. \u5d4c\u5957\u5217\u8868\u63a8\u5bfc\u5f0f<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#id12\"><\/a><\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u53d7\u7684\u4e86\u7684\u8bdd, \u5176\u5b9e\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u53ef\u4ee5\u5d4c\u5957\u7684. \u5b83\u7684\u786e\u662f\u4e2a\u5f3a\u5927\u7684\u5de5\u5177, \u4f46 \u2013 \u5c31\u50cf\u6240\u6709\u5f3a\u5927\u7684\u5de5\u5177\u4e00\u6837 \u2013 \u9700\u8981\u88ab\u5c0f\u5fc3\u5730\u4f7f\u7528,<\/p>\n\n\n\n<p>\u8003\u8651\u4e0b\u9762\u7684\u4f8b\u5b50, \u6709\u4e00\u4e2a 3\u00d73 \u7684\u77e9\u9635, \u5b58\u50a8\u4e3a\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5217\u8868\u7684\u5217\u8868, \u6bcf\u4e00\u884c\u4e00\u4e2a\u5217\u8868:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>mat = [<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>\u2026<\/strong>\u00a0[1, 2, 3],<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>\u2026<\/strong>\u00a0[4, 5, 6],\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">  <strong>\u2026<\/strong>\u00a0[7, 8, 9],\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0]<\/p>\n\n\n\n<p>\u73b0\u5728, \u5982\u679c\u4f60\u60f3\u4ea4\u6362\u884c\u548c\u5217, \u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>print([[row[i]\u00a0<strong>for<\/strong>\u00a0row\u00a0<strong>in<\/strong>\u00a0mat]\u00a0<strong>for<\/strong>\u00a0i\u00a0<strong>in<\/strong>\u00a0[0, 1, 2]]) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[[1, 4, 7], [2, 5, 8], [3, 6, 9]]<\/p>\n\n\n\n<p>\u4f7f\u7528*\u5d4c\u5957*\u5217\u8868\u63a8\u5bfc\u5f0f\u65f6\u7279\u522b\u9700\u8981\u6ce8\u610f:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u4ece\u53f3\u81f3\u5de6\u5730\u9605\u8bfb\u5d4c\u5957\u5217\u8868\u63a8\u5bfc\u5f0f\u66f4\u5bb9\u6613\u7406\u89e3.<\/p>\n<\/blockquote>\n\n\n\n<p>\u8be5\u4ee3\u7801\u7684\u5197\u957f\u7248\u672c, \u5c31\u660e\u767d\u5730\u8868\u8ff0\u4e86\u6d41\u7a0b:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>for<\/strong>\u00a0i\u00a0<strong>in<\/strong>\u00a0[0, 1, 2]:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>for<\/strong>\u00a0row\u00a0<strong>in<\/strong>\u00a0mat: <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">print(row[i], end=\u201d\u201d) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">print()<\/p>\n\n\n\n<p>\u73b0\u5b9e\u4e2d, \u4f60\u5e94\u5f53\u9009\u62e9\u5185\u5efa\u51fd\u5f0f\u6765\u5904\u7406\u590d\u6742\u6d41\u7a0b. \u8fd9\u91cc, \u51fd\u5f0f\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#zip\"><code>zip()<\/code><\/a>\u00a0\u5c31\u975e\u5e38\u597d\u7528.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>list(zip(*mat)) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[(1, 4, 7), (2, 5, 8), (3, 6, 9)]<\/p>\n\n\n\n<p>\u53c2\u89c1&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/controlflow.html#tut-unpacking-arguments\">\u53c2\u6570\u5217\u8868\u89e3\u5305<\/a>&nbsp;\u4e86\u89e3\u672c\u884c\u4e2d\u661f\u53f7\u7684\u8be6\u7ec6\u5185\u5bb9.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.2.&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#del\"><code>del<\/code><\/a>&nbsp;\u8bed\u53e5<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#del\"><\/a><\/h2>\n\n\n\n<p>\u8fd9\u6709\u4e00\u79cd\u901a\u8fc7\u7ed9\u5b9a\u7d22\u5f15\u800c\u4e0d\u662f\u503c, \u6765\u5220\u9664\u5217\u8868\u4e2d\u9879\u7684\u65b9\u6cd5: \u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#del\"><code>del<\/code><\/a>\u00a0\u8bed\u53e5. \u5b83\u4e0e\u8fd4\u56de\u4e00\u4e2a\u503c\u7684\u00a0<code>pop()<\/code>\u00a0\u65b9\u6cd5\u4e0d\u540c.\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#del\"><code>del<\/code><\/a>\u00a0\u8bed\u53e5\u4e5f\u53ef\u4ee5\u79fb\u9664\u5217\u8868\u4e2d\u7684\u5207\u7247, \u6216\u8005\u6e05\u9664\u6574\u4e2a\u5217\u8868 (\u4e4b\u524d\u6211\u4eec\u901a\u8fc7\u7ed9\u5207\u7247\u8d4b\u503c\u4e3a\u7a7a\u5217\u8868\u6765\u5b8c\u6210\u8fd9\u70b9). \u4f8b\u5982:<\/p>\n\n\n\n<p><strong>>>>\u00a0<\/strong>a = [-1, 1, 66.25, 333, 333, 1234.5]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0del<\/strong>\u00a0a[0]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [1, 66.25, 333, 333, 1234.5]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0del<\/strong>\u00a0a[2:4]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[1, 66.25, 1234.5]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0del<\/strong>\u00a0a[:]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[]<\/p>\n\n\n\n<p><a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#del\"><code>del<\/code><\/a>\u00a0\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5220\u9664\u53d8\u91cf\u5b9e\u4f53:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0del<\/strong>\u00a0a<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e4b\u540e\u5f15\u7528&nbsp;<code>a<\/code>&nbsp;\u7684\u8bdd\u4f1a\u4ea7\u751f\u4e00\u4e2a\u9519\u8bef (\u81f3\u5c11\u5230\u7ed9\u5b83\u8d4b\u53e6\u4e00\u4e2a\u503c\u4e4b\u524d). \u6211\u4eec\u5c06\u5728\u540e\u9762\u627e\u5230&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#del\"><code>del<\/code><\/a>&nbsp;\u7684\u5176\u5b83\u7528\u6cd5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.3. \u5143\u7ec4\u548c\u5e8f\u5217<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-tuples\"><\/a><\/h2>\n\n\n\n<p>\u6211\u4eec\u770b\u5230\u5217\u8868\u548c\u5b57\u4e32\u6709\u5f88\u591a\u901a\u7528\u7684\u5c5e\u6027, \u4f8b\u5982\u7d22\u5f15\u548c\u5207\u7247\u64cd\u4f5c. \u5b83\u4eec\u662f&nbsp;<strong>\u5e8f\u5217<\/strong>&nbsp;\u6570\u636e\u7c7b\u578b\u7684\u4e24\u4e2a\u4f8b\u5b50 (\u53c2\u8003&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/stdtypes.html#typesseq\">Sequence Types \u2014 str, bytes, bytearray, list, tuple, range<\/a>). Python \u4f5c\u4e3a\u4e00\u95e8\u8fdb\u5316\u4e2d\u7684\u8bed\u8a00, \u53ef\u80fd\u8fd8\u6709\u5176\u5b83\u5e8f\u5217\u7c7b\u578b\u4f1a\u88ab\u52a0\u5165. \u8fd9\u91cc\u5c31\u6709\u53e6\u4e00\u79cd\u6807\u51c6\u5e8f\u5217\u6570\u636e\u7c7b\u578b:&nbsp;<strong>\u5143\u7ec4<\/strong>&nbsp;.<\/p>\n\n\n\n<p>\u5143\u7ec4\u7531\u82e5\u5e72\u9017\u53f7\u5206\u9694\u7684\u503c\u7ec4\u6210, \u4f8b\u5982:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>t = 12345, 54321, \u2018hello!\u2019\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>t[0] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">12345\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>t<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> (12345, 54321, \u2018hello!\u2019)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong><em># Tuples may be nested:<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026\u00a0<\/strong>u = t, (1, 2, 3, 4, 5)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>u <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">((12345, 54321, \u2018hello!\u2019), (1, 2, 3, 4, 5))<\/p>\n\n\n\n<p>\u5982\u4f60\u6240\u89c1, \u5143\u7ec4\u8f93\u51fa\u65f6\u7528\u5706\u62ec\u53f7\u5305\u56f4, \u4ee5\u4fbf\u6b63\u786e\u8868\u8fbe\u5143\u7ec4\u7684\u5d4c\u5957; \u5728\u8f93\u5165\u65f6\u5706\u62ec\u53f7\u53ef\u52a0\u53ef\u4e0d\u52a0, \u4e0d\u8fc7\u5706\u62ec\u53f7\u7ecf\u5e38\u662f\u5fc5\u8981\u7684 (\u7279\u522b\u662f\u5f53\u5143\u7ec4\u662f\u66f4\u5927\u7684\u8868\u8fbe\u5f0f\u7684\u4e00\u90e8\u5206\u65f6).<\/p>\n\n\n\n<p>\u5143\u7ec4\u6709\u8bb8\u591a\u7528\u9014. \u4f8b\u5982: (x, y) \u5750\u6807\u5bf9, \u6570\u636e\u5e93\u91cc\u7684\u5458\u5de5\u8bb0\u5f55\u7b49. \u5143\u7ec4\u540c\u5b57\u4e32\u90fd\u662f\u4e0d\u53ef\u53d8\u7684: \u65e0\u6cd5\u5bf9\u5143\u7ec4\u6307\u5b9a\u9879\u8fdb\u884c\u8d4b\u503c (\u5c3d\u7ba1\u53ef\u901a\u8fc7\u5207\u7247\u548c\u8fde\u63a5\u6765\u6a21\u62df\u8fd9\u4e2a\u64cd\u4f5c). \u5143\u7ec4\u4e2d\u53ef\u4ee5\u5305\u542b\u53ef\u53d8\u7684\u5bf9\u8c61, \u5982\u5217\u8868.<\/p>\n\n\n\n<p>\u6784\u9020\u5305\u542b 0 \u6216 1 \u4e2a\u9879\u7684\u5143\u7ec4\u662f\u4e2a\u7279\u6b8a\u95ee\u9898: \u8bed\u6cd5\u4e0a\u4e3a\u4e86\u9002\u5e94\u8fd9\u4e00\u60c5\u51b5,\u6709\u4e9b\u989d\u5916\u7684\u89c4\u5219. \u7a7a\u5143\u7ec4\u7531\u4e00\u5bf9\u7a7a\u7684\u5706\u62ec\u53f7\u6784\u9020; \u4e00\u4e2a\u9879\u7684\u5143\u7ec4\u7531\u4e00\u4e2a\u503c\u540e\u9762\u8ddf\u7740\u4e00\u4e2a\u9017\u53f7\u6784\u9020 (\u628a\u4e00\u4e2a\u503c\u653e\u5165\u4e00\u5bf9\u5706\u62ec\u53f7\u91cc\u5e76\u4e0d\u8db3\u4ee5\u6784\u9020\u4e00\u4e2a\u5143\u7ec4). \u4e11\u964b, \u4f46\u6709\u6548. \u4f8b\u5982:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>empty = ()\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>singleton = \u2018hello\u2019,\u00a0<em># &lt;\u2013 \u6ce8\u610f\u540e\u9762\u7684\u9017\u53f7<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>len(empty)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> 0\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>len(singleton) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">1\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>singleton <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">(\u2018hello\u2019,)<\/p>\n\n\n\n<p>\u8bed\u53e5\u00a0<code>t\u00a0=\u00a012345,\u00a054321,\u00a0'hello!'<\/code>\u00a0\u662f\u00a0<strong>\u5143\u7ec4\u6253\u5305<\/strong>\u00a0\u7684\u4e00\u4e2a\u4f8b\u5b50: \u503c\u00a0<code>12345<\/code>,\u00a0<code>54321<\/code>\u00a0\u548c\u00a0<code>'hello!'<\/code>\u00a0\u88ab\u6253\u5305\u8fdb\u4e00\u4e2a\u5143\u7ec4. \u53cd\u8fc7\u6765, \u8fd9\u4e2a\u64cd\u4f5c\u4e5f\u662f\u53ef\u884c\u7684:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>x, y, z = t<\/p>\n\n\n\n<p>\u8fd9\u79cd\u5bf9\u53f3\u4fa7\u4efb\u4e00\u5e8f\u5217\u7684\u5904\u7406\u5f88\u5408\u9002\u79f0\u4e3a&nbsp;<strong>\u5e8f\u5217\u89e3\u5305<\/strong>&nbsp;. \u5e8f\u5217\u89e3\u5305\u65f6\u8981\u6c42\u7b49\u53f7\u5de6\u8fb9\u7684\u503c\u4e2a\u6570\u4e0e\u53f3\u8fb9\u5e8f\u5217\u5143\u7d20\u4e2a\u6570\u76f8\u7b49. \u6ce8\u610f, \u591a\u91cd\u8d4b\u503c\u5176\u5b9e\u662f\u8054\u5408\u4f7f\u7528\u4e86\u5143\u7ec4\u6253\u5305\u548c\u5e8f\u5217\u89e3\u5305. (\u867d\u7136\u5143\u7ec4\u548c\u5217\u8868\u90fd\u7b97\u5e8f\u5217,\u4f46\u662f\u5fc5\u987b\u6709\u6240\u4e0d\u540c)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.4. \u96c6\u5408(Set)<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#set\"><\/a><\/h2>\n\n\n\n<p>Python \u8fd8\u5305\u542b\u4e86&nbsp;<em>\u96c6\u5408(set)<\/em>&nbsp;\u6570\u636e\u7c7b\u578b. \u96c6\u5408\u662f\u79cd\u65e0\u5e8f\u4e0d\u91cd\u590d\u7684\u5143\u7d20\u96c6. \u57fa\u672c\u7528\u9014\u5305\u62ec\u6210\u5458\u5173\u7cfb\u6d4b\u8bd5\u548c\u91cd\u590d\u6761\u76ee\u6d88\u9664. \u96c6\u5408\u5bf9\u8c61\u4e5f\u652f\u6301\u5408(union),\u4ea4(intersection), \u5dee(difference), \u548c\u5bf9\u79f0\u5dee(sysmmetric difference)\u7b49\u6570\u5b66\u64cd\u4f5c.<\/p>\n\n\n\n<p>\u82b1\u62ec\u53f7\u6216\u51fd\u5f0f&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/stdtypes.html#set\"><code>set()<\/code><\/a>&nbsp;\u53ef\u7528\u4e8e\u521b\u5efa\u96c6\u5408. \u6ce8\u610f: \u521b\u5efa\u4e00\u4e2a\u7a7a\u96c6\u5408\u53ea\u80fd\u4f7f\u7528&nbsp;<code>set()<\/code>, \u800c\u4e0d\u80fd\u4f7f\u7528&nbsp;<code>{}<\/code>; \u540e\u8005\u662f\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178, \u5b57\u5178\u6211\u4eec\u4f1a\u5728\u4e0b\u4e00\u8282\u91cc\u8ba8\u8bba.<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u7b80\u660e\u793a\u8303:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>basket = {\u2018apple\u2019, \u2018orange\u2019, \u2018apple\u2019, \u2018pear\u2019, \u2018orange\u2019, \u2018banana\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>print(basket)\u00a0<em># \u91cd\u590d\u7684\u88ab\u79fb\u9664\u4e86<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0{\u2018orange\u2019, \u2018banana\u2019, \u2018pear\u2019, \u2018apple\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>\u2018orange\u2019\u00a0<strong>in<\/strong>\u00a0basket\u00a0<em># \u5feb\u901f\u6210\u5458\u5173\u7cfb\u6d4b\u8bd5<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0True\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>\u2018crabgrass\u2019\u00a0<strong>in<\/strong>\u00a0basket False\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong><em># \u5728\u4e24\u4e2a\u5355\u8bcd\u7684\u4e0d\u91cd\u590d\u7684\u5b57\u6bcd\u91cc\u6f14\u793a\u96c6\u5408\u64cd\u4f5c<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a = set(\u2018abracadabra\u2019)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>b = set(\u2018alacazam\u2019)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a\u00a0<em># a \u4e2d\u7684\u4e0d\u91cd\u590d\u5b57\u6bcd<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018a\u2019, \u2018r\u2019, \u2018b\u2019, \u2018c\u2019, \u2018d\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a \u2013 b\u00a0<em># a \u4e2d\u6709\u800c b \u4e2d\u6ca1\u6709\u7684\u5b57\u6bcd<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0{\u2018r\u2019, \u2018d\u2019, \u2018b\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a | b\u00a0<em># \u65e2\u6709 a \u7684\u5b57\u6bcd\u53c8\u6709 b \u7684\u5b57\u6bcd<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018a\u2019, \u2018c\u2019, \u2018r\u2019, \u2018d\u2019, \u2018b\u2019, \u2018m\u2019, \u2018z\u2019, \u2018l\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a &amp; b\u00a0<em># a \u548c b \u4e2d\u90fd\u6709\u7684\u5b57\u6bcd<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018a\u2019, \u2018c\u2019}<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>a ^ b\u00a0<em># a \u6216 b \u4e2d\u53ea\u6709\u4e00\u4e2a\u6709\u7684\u5b57\u6bcd<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018r\u2019, \u2018d\u2019, \u2018b\u2019, \u2018m\u2019, \u2018z\u2019, \u2018l\u2019}<\/p>\n\n\n\n<p>\u5c31\u50cf\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-listcomps\">\u5217\u8868<\/a>, \u96c6\u5408\u4e5f\u652f\u6301\u63a8\u5bfc\u5f0f:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a = {x\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0\u2018abracadabra\u2019\u00a0<strong>if<\/strong>\u00a0x\u00a0<strong>notin<\/strong>\u00a0\u2018abc\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> {\u2018r\u2019, \u2018d\u2019}<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.5. \u5b57\u5178<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-dictionaries\"><\/a><\/h2>\n\n\n\n<p>Python \u4e2d\u53e6\u4e00\u5f88\u6709\u7528\u7684\u5185\u5efa\u6570\u636e\u7c7b\u578b\u4e3a&nbsp;<em>\u5b57\u5178<\/em>&nbsp;(\u53c2\u8003&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/stdtypes.html#typesmapping\">Mapping Types \u2014 dict<\/a>). \u5728\u5176\u5b83\u8bed\u8a00\u4e2d\u5b57\u5178\u4e00\u822c\u88ab\u53eb\u505a \u201c\u5173\u8054\u5b58\u50a8\u201d \u6216 \u201c\u5173\u8054\u6570\u7ec4\u201d. \u4e0e\u4f7f\u7528\u67d0\u4e2a\u8303\u56f4\u4f5c\u4e3a\u7d22\u5f15\u7684\u5e8f\u5217\u4e0d\u4e00\u6837, \u5b57\u5178\u901a\u8fc7&nbsp;<em>\u952e<\/em>&nbsp;\u6765\u7d22\u5f15, \u800c\u952e\u53ef\u4ee5\u662f\u4efb\u610f\u4e0d\u53ef\u53d8\u7c7b\u578b; \u901a\u5e38\u7528\u5b57\u7b26\u4e32\u548c\u6570\u5b57\u4f5c\u4e3a\u952e. \u5982\u679c\u5143\u7ec4\u53ea\u5305\u542b\u5b57\u7b26\u4e32\u548c\u6570\u5b57, \u5143\u7ec4\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u952e; \u4f46\u662f, \u5f53\u5143\u7ec4\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u5305\u542b\u53ef\u53d8\u5bf9\u8c61\u65f6, \u5c31\u4e0d\u80fd\u7528\u4f5c\u4e00\u4e2a\u952e. \u4e0d\u80fd\u4f7f\u7528\u5217\u8868\u4f5c\u4e3a\u952e, \u56e0\u4e3a\u5217\u8868\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15, \u5207\u7247, \u6216\u5982&nbsp;<code>append()<\/code>&nbsp;\u548c&nbsp;<code>extend()<\/code>&nbsp;\u65b9\u6cd5\u539f\u5730\u8d4b\u503c\u800c\u88ab\u6539\u53d8.<\/p>\n\n\n\n<p>\u6700\u597d\u628a\u5b57\u5178\u770b\u6210\u662f\u4e00\u4e2a\u6ca1\u6709\u987a\u5e8f\u7684&nbsp;<em>\u952e:\u503c<\/em>&nbsp;\u5bf9\u96c6\u5408, \u952e\u5fc5\u987b\u662f\u552f\u4e00\u7684 (\u5728\u4e00\u4e2a\u5b57\u5178\u91cc). \u4e00\u5bf9\u82b1\u62ec\u53f7\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178:&nbsp;<code>{}<\/code>. \u5728\u62ec\u53f7\u4e2d\u95f4\u653e\u7f6e\u7684\u4ee5\u9017\u53f7\u5206\u9694\u7684&nbsp;<code>\u952e:\u503c\u5bf9<\/code>&nbsp;\u5217\u8868\u5c31\u662f\u5b57\u5178\u7684\u521d\u59cb&nbsp;<code>\u952e:\u503c\u5bf9<\/code>. \u8fd9\u4e5f\u662f\u5b57\u5178\u8f93\u51fa\u65f6\u7684\u683c\u5f0f.<\/p>\n\n\n\n<p>\u5b57\u5178\u6700\u4e3b\u8981\u7684\u64cd\u4f5c\u662f\u901a\u8fc7\u67d0\u952e\u5b58\u50a8\u4e00\u4e2a\u503c, \u4ee5\u53ca\u4ece\u7ed9\u5b9a\u7684\u952e\u91cc\u63d0\u53d6\u5b83\u7684\u503c. \u4f7f\u7528&nbsp;<code>del<\/code>&nbsp;\u53ef\u4ee5\u5220\u9664\u4e00\u4e2a\u952e:\u503c\u5bf9. \u5982\u679c\u4f60\u4f7f\u7528\u4e00\u4e2a\u5df2\u88ab\u4f7f\u7528\u7684\u952e\u8fdb\u884c\u5b58\u50a8\u64cd\u4f5c, \u8be5\u952e\u7684\u65e7\u503c\u5c31\u6ca1\u6709\u4e86. \u4f7f\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u952e\u63d0\u53d6\u503c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u9519\u8bef.<\/p>\n\n\n\n<p>\u5728\u4e00\u4e2a\u5b57\u5178\u4e0a\u6267\u884c&nbsp;<code>list(d.keys())<\/code>&nbsp;\u8fd4\u56de\u8be5\u5b57\u5178\u4e2d\u6240\u4f7f\u7528\u952e\u7684\u5217\u8868, \u8be5\u5217\u8868\u7684\u987a\u5e8f\u4e0d\u786e\u5b9a (\u5982\u679c\u9700\u8981\u6709\u5e8f, \u53ea\u8981\u4f7f\u7528&nbsp;<code>sorted(d.keys())<\/code>).&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#id19\">[1]<\/a>&nbsp;\u8981\u68c0\u67e5\u67d0\u4e00\u4e2a\u952e\u662f\u5426\u5728\u5b57\u5178\u91cc, \u4f7f\u7528&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/expressions.html#in\"><code>in<\/code><\/a>&nbsp;\u5173\u952e\u5b57.<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u4f7f\u7528\u5b57\u5178\u7684\u5c0f\u4f8b\u5b50:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>tel = {\u2018jack\u2019: 4098, \u2018sape\u2019: 4139}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>tel[\u2018guido\u2019] = 4127<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>tel <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018sape\u2019: 4139, \u2018guido\u2019: 4127, \u2018jack\u2019: 4098}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>tel[\u2018jack\u2019] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">4098\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0del<\/strong>\u00a0tel[\u2018sape\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>tel[\u2018irv\u2019] = 4127\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>tel <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018guido\u2019: 4127, \u2018irv\u2019: 4127, \u2018jack\u2019: 4098}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>list(tel.keys()) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[\u2018irv\u2019, \u2018guido\u2019, \u2018jack\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>sorted(tel.keys())<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [\u2018guido\u2019, \u2018irv\u2019, \u2018jack\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>\u2018guido\u2019\u00a0<strong>in<\/strong>\u00a0tel <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">True<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>\u2018jack\u2019\u00a0<strong>notin<\/strong>\u00a0tel <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">False<\/p>\n\n\n\n<p>\u6784\u9020\u5668\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/stdtypes.html#dict\"><code>dict()<\/code><\/a>\u00a0\u4ece\u952e-\u503c\u5bf9\u5e8f\u5217\u91cc\u76f4\u63a5\u751f\u6210\u5b57\u5178,\u5982\u679c\u6709\u56fa\u5b9a\u7684\u6a21\u5f0f,\u53ef\u5728\u5217\u8868\u63a8\u5bfc\u5f0f\u6307\u5b9a\u7279\u5b9a\u7684\u952e\u503c\u5bf9:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>dict([(\u2018sape\u2019, 4139), (\u2018guido\u2019, 4127), (\u2018jack\u2019, 4098)]) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{\u2018sape\u2019: 4139, \u2018jack\u2019: 4098, \u2018guido\u2019: 4127}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>dict([(x, x**2)\u00a0<strong>for<\/strong>\u00a0x\u00a0<strong>in<\/strong>\u00a0(2, 4, 6)])\u00a0<em># \u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">{2: 4, 4: 16, 6: 36}<\/p>\n\n\n\n<p>\u5728\u672c\u6559\u7a0b\u540e\u9762\u7684\u7ae0\u8282, \u4f1a\u5b66\u4e60\u5230\u751f\u6210\u5668\u8868\u8fbe\u5f0f, \u8fd9\u66f4\u9002\u4e8e\u4e3a\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/stdtypes.html#dict\"><code>dict()<\/code><\/a>\u00a0\u6784\u9020\u5668\u751f\u6210\u952e-\u503c\u5bf9\u5e8f\u5217. \u82e5\u952e\u4e3a\u5b57\u7b26\u4e32, \u6709\u65f6\u7528\u5173\u952e\u5b57\u53c2\u6570\u6307\u5b9a\u952e-\u503c\u5bf9\u66f4\u4e3a\u7b80\u5355:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>dict(sape=4139, guido=4127, jack=4098)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> {\u2018sape\u2019: 4139, \u2018jack\u2019: 4098, \u2018guido\u2019: 4127}<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.6. \u904d\u5386\u6280\u5de7<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-loopidioms\"><\/a><\/h2>\n\n\n\n<p>\u5f53\u5bf9\u5b57\u5178\u904d\u5386\u65f6, \u53ef\u7528\u00a0<code>items()<\/code>\u00a0\u65b9\u6cd5\u540c\u65f6\u53d6\u56de\u952e\u548c\u5bf9\u5e94\u7684\u503c.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>knights = {\u2018gallahad\u2019: \u2018the pure\u2019, \u2018robin\u2019: \u2018the brave\u2019}\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0for<\/strong>\u00a0k, v\u00a0<strong>in<\/strong>\u00a0knights.items():\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0print(k, v)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">gallahad the pure <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">robin the brave<\/p>\n\n\n\n<p>\u5bf9\u5e8f\u5217\u904d\u5386\u65f6, \u53ef\u4ee5\u4f7f\u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#enumerate\"><code>enumerate()<\/code><\/a>\u00a0\u51fd\u5f0f\u6765\u540c\u65f6\u53d6\u56de\u4f4d\u7f6e\u7d22\u5f15\u548c\u76f8\u5e94\u7684\u503c.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0for<\/strong>\u00a0i, v\u00a0<strong>in<\/strong>\u00a0enumerate([\u2018tic\u2019, \u2018tac\u2019, \u2018toe\u2019]):<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>\u2026<\/strong>\u00a0print(i, v)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">0 tic<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> 1 tac 2<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> toe<\/p>\n\n\n\n<p class=\"has-palette-color-7-background-color has-background\">\u540c\u65f6\u5bf9\u4e24\u4e2a\u6216\u66f4\u591a\u7684\u5e8f\u5217\u8fdb\u884c\u904d\u5386\u65f6, \u53ef\u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#zip\"><code>zip()<\/code><\/a>\u00a0\u8fdb\u884c\u7ec4\u5408<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>questions = [\u2018name\u2019, \u2018quest\u2019, \u2018favorite color\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>answers = [\u2018lancelot\u2019, \u2018the holy grail\u2019, \u2018blue\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0for<\/strong>\u00a0q, a\u00a0<strong>in<\/strong>\u00a0zip(questions, answers):<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>\u2026<\/strong>\u00a0print(\u2018What is your\u00a0<em>{0}<\/em>? It is\u00a0<em>{1}<\/em>.\u2019.format(q, a))\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">What is your name? It is lancelot.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> What is your quest? It is the holy grail. <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">What is your favorite color? It is blue.<\/p>\n\n\n\n<p>\u53cd\u5411\u904d\u5386\u5e8f\u5217\u65f6, \u5148\u6307\u5b9a\u8fd9\u4e2a\u5e8f\u5217, \u7136\u540e\u8c03\u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#reversed\"><code>reversed()<\/code><\/a>\u00a0\u51fd\u5f0f<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0for<\/strong>\u00a0i\u00a0<strong>in<\/strong>\u00a0reversed(range(1, 10, 2)):\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0print(i)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">9   7   5   3   1<\/p>\n\n\n\n<p>\u60f3\u6709\u5e8f\u5730\u904d\u5386\u4e00\u4e2a\u5e8f\u5217, \u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#sorted\"><code>sorted()<\/code><\/a>\u00a0\u51fd\u5f0f\u8fd4\u56de\u6392\u5e8f\u540e\u7684\u5e8f\u5217,\u539f\u5e8f\u5217\u5c06\u4e0d\u88ab\u89e6\u53ca<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>basket = [\u2018apple\u2019, \u2018orange\u2019, \u2018apple\u2019, \u2018pear\u2019, \u2018orange\u2019, \u2018banana\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0for<\/strong>\u00a0f\u00a0<strong>in<\/strong>\u00a0sorted(set(basket)):<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>\u2026<\/strong>\u00a0print(f)\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>\u2026<\/strong>\u00a0apple <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">banana <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">orange <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">pear<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.7. \u6df1\u5165\u6761\u4ef6\u63a7\u5236<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-conditions\"><\/a><\/h2>\n\n\n\n<p>\u5728&nbsp;<code>while<\/code>&nbsp;\u548c&nbsp;<code>if<\/code>&nbsp;\u8bed\u53e5\u4e2d\u4f7f\u7528\u7684\u6761\u4ef6\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u64cd\u4f5c\u7b26, \u800c\u4e0d\u4ec5\u4ec5\u662f\u6bd4\u8f83.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bd4\u8f83\u64cd\u4f5c\u7b26&nbsp;<code>in<\/code>&nbsp;\u548c&nbsp;<code>not&nbsp;in<\/code>&nbsp;\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5728\u5e8f\u5217\u4e2d.<\/li>\n\n\n\n<li>\u64cd\u4f5c\u7b26&nbsp;<code>is<\/code>&nbsp;\u548c&nbsp;<code>is&nbsp;not<\/code>&nbsp;\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u4e3a\u540c\u4e00\u5bf9\u8c61; \u8fd9\u53ea\u5bf9\u8bf8\u5982\u5217\u8868\u7684\u53ef\u53d8\u5bf9\u8c61\u6709\u7528.<\/li>\n<\/ul>\n\n\n\n<p>\u6240\u6709\u6bd4\u8f83\u64cd\u4f5c\u7b26\u5177\u6709\u76f8\u540c\u7684\u4f18\u5148\u7ea7, \u4f4e\u4e8e\u6240\u6709\u7684\u6570\u503c\u64cd\u4f5c.<\/p>\n\n\n\n<p>\u6bd4\u8f83\u64cd\u4f5c\u7b26\u53ef\u4ee5\u8fde\u8d77\u6765\u4f7f\u7528. \u4f8b\u5982, \u2013&nbsp;<code>a&nbsp;&lt;&nbsp;b&nbsp;==&nbsp;c<\/code>&nbsp;\u6d4b\u8bd5&nbsp;<code>a<\/code>&nbsp;\u5c0f\u4e8e&nbsp;<code>b<\/code>&nbsp;\u4e14&nbsp;<code>b<\/code>&nbsp;\u4e0e&nbsp;<code>c<\/code>&nbsp;\u76f8\u7b49.<\/p>\n\n\n\n<p>\u6bd4\u8f83\u64cd\u4f5c(\u6216\u5176\u5b83\u4efb\u4f55\u5e03\u5c14\u8868\u8fbe\u5f0f)\u90fd\u80fd\u7528\u903b\u8f91\u64cd\u4f5c\u7b26&nbsp;<code>and<\/code>&nbsp;\u548c&nbsp;<code>or<\/code>&nbsp;\u8fde\u63a5, \u7ed3\u679c\u503c\u53ef\u4ee5\u7528&nbsp;<code>not<\/code>&nbsp;\u53d6\u53cd.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u903b\u8f91\u64cd\u4f5c\u7b26\u7684\u4f18\u5148\u7ea7\u53c8\u4f4e\u4e8e\u6bd4\u8f83\u64cd\u4f5c\u7b26;<\/li>\n\n\n\n<li>\u8fd9\u5176\u4e2d,&nbsp;<code>not<\/code>&nbsp;\u4f18\u5148\u7ea7\u6700\u9ad8, \u800c&nbsp;<code>or<\/code>&nbsp;\u7684\u4f18\u5148\u7ea7\u6700\u4f4e, \u56e0\u6b64&nbsp;<code>A&nbsp;and&nbsp;not&nbsp;B&nbsp;or&nbsp;C<\/code>&nbsp;\u7b49\u4ef7\u4e8e&nbsp;<code>(A&nbsp;and&nbsp;(not&nbsp;B))&nbsp;or&nbsp;C<\/code>&nbsp;. \u540c\u6837, \u53ef\u4ee5\u4f7f\u7528\u5706\u62ec\u53f7\u6765\u8868\u8fbe\u60f3\u8981\u7684\u7ed3\u679c.<\/li>\n\n\n\n<li>\u903b\u8f91\u64cd\u4f5c\u7b26&nbsp;<code>and<\/code>&nbsp;\u548c&nbsp;<code>or<\/code>&nbsp;\u88ab\u79f0\u4e3a&nbsp;<em>\u77ed\u8def<\/em>&nbsp;\u64cd\u4f5c\u7b26: \u5b83\u4ece\u5de6\u81f3\u53f3\u8ba1\u7b97\u53c2\u6570,\u5e76\u4e14\u5f53\u7ed3\u679c\u786e\u5b9a\u65f6\u8ba1\u7b97\u5c31\u7acb\u5373\u505c\u6b62.\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982, \u5982\u679c&nbsp;<code>A<\/code>&nbsp;\u548c&nbsp;<code>C<\/code>&nbsp;\u4e3a\u771f, \u800c&nbsp;<code>B<\/code>&nbsp;\u4e3a\u5047\u65f6,&nbsp;<code>A&nbsp;and&nbsp;B&nbsp;and&nbsp;C<\/code>&nbsp;\u4e0d\u4f1a\u8ba1\u7b97\u8868\u8fbe\u5f0f&nbsp;<code>C<\/code>.<\/li>\n\n\n\n<li>\u5f53\u628a\u77ed\u8def\u64cd\u4f5c\u7b26\u7684\u8fd4\u56de\u503c\u4f5c\u4e3a\u4e00\u4e2a\u5e38\u89c4\u503c\u800c\u4e0d\u662f\u5e03\u5c14\u503c\u65f6, \u5b83\u7684\u503c\u5c31\u662f\u6700\u540e\u8ba1\u7b97\u7684\u53c2\u6570\u503c.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u53ef\u4ee5\u628a\u6bd4\u8f83\u5f0f\u6216\u5176\u5b83\u903b\u8f91\u8868\u8fbe\u5f0f\u7684\u503c\u8d4b\u7ed9\u4e00\u4e2a\u53d8\u91cf. \u4f8b\u5982,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>string1, string2, string3 = \u201d, \u2018Trondheim\u2019, \u2018Hammer Dance\u2019<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>non_null = string1\u00a0<strong>or<\/strong>\u00a0string2\u00a0<strong>or<\/strong>\u00a0string3\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>non_null<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018Trondheim\u2019<\/p>\n\n\n\n<p>\u6ce8\u610f, \u5728 Python \u4e2d, \u4e0d\u50cf C, \u8d4b\u503c\u4e0d\u53ef\u4ee5\u53d1\u751f\u5728\u8868\u8fbe\u5f0f\u5185\u90e8. C \u7a0b\u5e8f\u5458\u53ef\u80fd\u5bf9\u6b64\u6709\u62b1\u6028, \u4f46\u662f\u8fd9\u6837\u5c31\u907f\u514d\u4e86 C \u7a0b\u5e8f\u4e2d\u5e38\u89c1\u7684\u4e00\u7c7b\u9519\u8bef,\u6bd4\u5982\u8bf4:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u4f7f\u7528&nbsp;<code>==<\/code>&nbsp;\u7684\u8868\u8fbe\u5f0f\u91cc\u952e\u5165\u4e86&nbsp;<code>=<\/code>&nbsp;.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5.8. \u5e8f\u5217\u548c\u5176\u5b83\u7c7b\u578b\u7684\u6bd4\u8f83<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/datastructures.html#tut-comparing\"><\/a><\/h2>\n\n\n\n<p>\u5e8f\u5217\u5bf9\u8c61\u53ef\u4ee5\u4e0e\u540c\u4e00\u7c7b\u578b\u7684\u5176\u5b83\u5bf9\u8c61\u6bd4\u8f83. \u4f7f\u7528&nbsp;<em>\u5b57\u5178\u7f16\u7e82<\/em>&nbsp;\u987a\u5e8f\u6bd4\u8f83:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9996\u5148\u6bd4\u8f83\u5934\u4e24\u9879, \u5982\u679c\u5b83\u4eec\u4e0d\u540c, \u5b83\u4eec\u7684\u6bd4\u8f83\u5c31\u51b3\u5b9a\u6574\u4e2a\u6bd4\u8f83\u7684\u7ed3\u679c;<\/li>\n\n\n\n<li>\u5982\u679c\u5b83\u4eec\u76f8\u540c, \u5c31\u6bd4\u8f83\u4e0b\u4e24\u9879, \u5c31\u8fd9\u6837\u76f4\u5230\u5176\u4e2d\u6709\u5e8f\u5217\u88ab\u6bd4\u8f83\u5b8c\u4e86.<\/li>\n\n\n\n<li>\u5982\u679c\u8981\u88ab\u6bd4\u8f83\u7684\u4e24\u9879\u672c\u8eab\u5c31\u662f\u76f8\u540c\u7c7b\u578b\u7684\u5e8f\u5217, \u90a3\u4e48\u5c31\u9012\u5f52\u8fdb\u884c\u6bd4\u8f83.<\/li>\n\n\n\n<li>\u5982\u679c\u4e24\u4e2a\u5e8f\u5217\u6240\u6709\u7684\u9879\u90fd\u76f8\u7b49, \u90a3\u4e48, \u5b83\u4eec\u5c31\u76f8\u7b49.<\/li>\n\n\n\n<li>\u5982\u679c\u4e00\u4e2a\u5e8f\u5217\u662f\u53e6\u4e00\u4e2a\u5e8f\u5217\u7684\u521d\u59cb\u5b50\u5e8f\u5217(initial sub-sequence),\u90a3\u4e48\u77ed\u7684\u5c31\u662f\u8f83\u5c0f\u7684.<\/li>\n\n\n\n<li>\u5b57\u7b26\u4e32\u7684&nbsp;<em>\u5b57\u5178\u7f16\u7e82<\/em>&nbsp;\u987a\u5e8f\u7531\u5355\u4e2a\u5b57\u7b26\u7684 Unicode \u5b57\u7801\u6765\u51b3\u5b9a.<\/li>\n<\/ul>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u6bd4\u8f83\u76f8\u540c\u7c7b\u578b\u5e8f\u5217\u7684\u4f8b\u5b50:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"454\" height=\"132\" src=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/10\/image-5.png\" alt=\"\" class=\"wp-image-343\" srcset=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/10\/image-5.png 454w, http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/10\/image-5-300x87.png 300w\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" \/><\/figure>\n\n\n\n<p>\u6ce8\u610f, \u4f7f\u7528&nbsp;<code>&lt;<\/code>&nbsp;\u6216&nbsp;<code>&gt;<\/code>&nbsp;\u6bd4\u8f83\u4e24\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u6709\u65f6\u5019\u662f\u5408\u6cd5\u7684, \u6761\u4ef6\u662f\u5b83\u4eec\u8981\u6709\u5408\u9002\u7684\u6bd4\u8f83\u65b9\u6cd5. \u4f8b\u5982, \u4e0d\u540c\u7684\u6570\u5b57\u7c7b\u578b\u53ef\u4ee5\u6309\u7167\u5b83\u4eec\u7684\u6570\u5b57\u5927\u5c0f\u6765\u6bd4\u8f83, \u56e0\u6b64 0 \u7b49\u4e8e 0.0, \u7b49\u7b49. \u5426\u5219, \u89e3\u91ca\u5668\u4e0d\u4f1a\u63d0\u4f9b\u4e00\u4e2a\u4efb\u610f\u7684\u987a\u5e8f, \u800c\u4f1a\u629b\u51fa\u4e00\u4e2a&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/exceptions.html#TypeError\"><code>TypeError<\/code><\/a>&nbsp;\u5f02\u5e38.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p># \u5269\u4f59\u7684\u961f\u5217, \u5b83\u6309\u7167\u8fdb\u5165\u7684\u987a\u5e8f\u6392\u5217&nbsp;deque([\u2018Michael\u2019, \u2018Terry\u2019, \u2018Gr [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-277","post","type-post","status-publish","format-standard","hentry","category-python"],"blocksy_meta":"","_links":{"self":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":12,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/277\/revisions"}],"predecessor-version":[{"id":346,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/277\/revisions\/346"}],"wp:attachment":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}