{"id":76,"date":"2026-08-06T00:20:26","date_gmt":"2026-08-05T16:20:26","guid":{"rendered":"https:\/\/ltrainyard.icu\/?p=76"},"modified":"2026-08-06T00:42:33","modified_gmt":"2026-08-05T16:42:33","slug":"day-6-%e5%88%97%e8%a1%a8%e4%b8%8e%e5%85%83%e7%bb%84%ef%bc%9a%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e3%80%81%e5%88%87%e7%89%87%e4%b8%8e%e9%81%8d%e5%8e%86","status":"publish","type":"post","link":"https:\/\/ltrainyard.icu\/index.php\/2026\/08\/06\/day-6-%e5%88%97%e8%a1%a8%e4%b8%8e%e5%85%83%e7%bb%84%ef%bc%9a%e5%a2%9e%e5%88%a0%e6%94%b9%e6%9f%a5%e3%80%81%e5%88%87%e7%89%87%e4%b8%8e%e9%81%8d%e5%8e%86\/","title":{"rendered":"| Day 6 | \u5217\u8868\u4e0e\u5143\u7ec4\uff1a\u589e\u5220\u6539\u67e5\u3001\u5207\u7247\u4e0e\u904d\u5386 |"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 \u5217\u8868\u7684\u5e95\u5c42 \u2014\u2014 \u5185\u5b58\u4e2d\u7684\u8fde\u7eed\u8f66\u53a2<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5217\u8868<\/strong>\uff08list\uff09\u662f Python \u91cc\u6700\u5e38\u7528\u7684\u5bb9\u5668\uff1a\u4e00\u4e2a\u53d8\u91cf\u88c5\u591a\u4e2a\u503c\u3002\u4e4b\u524d\u5b66\u7684\u53d8\u91cf\u4e00\u6b21\u53ea\u80fd\u5b58\u4e00\u4e2a\u503c\uff0c\u4f46\u73b0\u5b9e\u4e2d\u5e38\u5e38\u6709\u4e00\u5806\u6570\u636e\u2014\u2014\u8d2d\u7269\u6e05\u5355\u6709 10 \u6837\u4e1c\u897f\u3001\u4e00\u4e2a\u73ed\u6709 30 \u4e2a\u6210\u7ee9\u3002\u5217\u8868\u5c31\u662f\u7528\u6765\u300c\u4e00\u6b21\u88c5\u4e00\u5806\u300d\u7684\u5bb9\u5668\u3002\u4e3a\u4ec0\u4e48\u96f6\u57fa\u7840\u5fc5\u5b66\uff1f\u4e86\u89e3\u5b83\u7684\u5e95\u5c42\u8bbe\u8ba1\uff0c\u4f60\u624d\u80fd\u7406\u89e3\u300c\u4e0b\u6807\u4e3a\u4ec0\u4e48\u4ece 0 \u5f00\u59cb\u300d\u300c\u4e3a\u4ec0\u4e48 insert \u6bd4 append \u6162\u300d\u8fd9\u4e9b\u9ad8\u9891\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u7684\u5217\u8868\u5728\u5185\u5b58\u91cc\u662f<strong>\u52a8\u6001\u6570\u7ec4<\/strong>\uff1a\u5b83\u7533\u8bf7\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\uff0c\u6bcf\u4e2a\u5143\u7d20\u5b58\u4e00\u4e2a\u300c\u5f15\u7528\u300d\uff08\u6307\u5411\u771f\u5b9e\u6570\u636e\u7684\u5730\u5740\uff0c\u7c7b\u4f3c\u5feb\u9012\u5355\u53f7\uff09\u3002\u56e0\u4e3a\u5b58\u7684\u662f\u5f15\u7528\u800c\u4e0d\u662f\u6570\u636e\u672c\u8eab\uff0c\u6240\u4ee5\u540c\u4e00\u4e2a\u5217\u8868\u91cc\u53ef\u4ee5\u6df7\u88c5\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5e03\u5c14\u503c\u3002\u6309\u4e0b\u6807\u53d6\u503c <code>fruits[2]<\/code> \u65f6\uff0cPython \u76f4\u63a5\u6309\u300c\u8d77\u59cb\u5730\u5740 + 2 \u00d7 \u6bcf\u4e2a\u5f15\u7528\u5360\u7684\u5b57\u8282\u6570\u300d\u7b97\u51fa\u4f4d\u7f6e\uff0c\u4e00\u6b65\u5230\u4f4d\u2014\u2014\u6240\u4ee5\u4e0b\u6807\u53d6\u503c\u6781\u5feb\uff0c\u8fd9\u4e5f\u662f\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u7684\u539f\u56e0\uff1a\u7b2c 1 \u4e2a\u5143\u7d20\u7684\u504f\u79fb\u91cf\u662f 0\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u672f\u8bed\u5c0f\u8bcd\u5178\uff1a<strong>\u5f15\u7528<\/strong>\uff08reference\uff09\u5c31\u662f\u300c\u6307\u5411\u771f\u5b9e\u6570\u636e\u7684\u5730\u5740\u7f16\u53f7\u300d\uff0c\u50cf\u5feb\u9012\u5355\u53f7\u2014\u2014\u51ed\u5355\u53f7\u53bb\u4ed3\u5e93\u53d6\u771f\u4e1c\u897f\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u50cf\u4e00\u5217<strong>\u706b\u8f66<\/strong>\uff1a\u8f66\u53a2\u4e00\u8282\u6328\u4e00\u8282\uff08\u5185\u5b58\u8fde\u7eed\uff09\uff0c\u6bcf\u8282\u8f66\u53a2\u91cc\u653e\u7684\u662f\u4e00\u5f20\u300c\u5feb\u9012\u5355\u53f7\u300d\uff08\u5f15\u7528\uff09\uff0c\u51ed\u5355\u53f7\u53bb\u4ed3\u5e93\u53d6\u771f\u4e1c\u897f\uff08\u6570\u636e\uff09\u3002\u60f3\u627e\u7b2c 3 \u8282\u8f66\u53a2\u7684\u4e1c\u897f\uff0c\u4ece\u8f66\u5934\u6570\u8fc7\u53bb\u5c31\u884c\u2014\u2014\u8fd9\u5c31\u662f\u6309\u4e0b\u6807\u53d6\u503c\u7684\u539f\u7406\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u4e00\u4e2a\u53d8\u91cf\u88c5\u591a\u4e2a\u503c + \u6309\u4e0b\u6807\u53d6<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits = &#91;\"\u82f9\u679c\", \"\u9999\u8549\", \"\u6a58\u5b50\", \"\u8461\u8404\"]\nprint(fruits&#91;0])     # \u7b2c\u4e00\u4e2a\u5143\u7d20\nprint(fruits&#91;1])     # \u7b2c\u4e8c\u4e2a\u5143\u7d20\nprint(fruits&#91;3])     # \u7b2c\u56db\u4e2a\u5143\u7d20\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u82f9\u679c\n\u9999\u8549\n\u8461\u8404\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u6570\uff0c\u6240\u4ee5\u4e0b\u6807 0\u30011\u30012\u30013 \u5bf9\u5e94\u7b2c\u4e00\u3001\u4e8c\u3001\u4e09\u3001\u56db\u4e2a\u5143\u7d20\u3002\u5199 <code>fruits[4]<\/code> \u5c31\u4f1a\u62a5 <code>IndexError<\/code>\uff08\u8d8a\u754c\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u8d1f\u6570\u4e0b\u6807\u2014\u2014\u4ece\u5c3e\u90e8\u6570<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits = &#91;\"\u82f9\u679c\", \"\u9999\u8549\", \"\u6a58\u5b50\"]\nprint(fruits&#91;-1])    # \u5012\u6570\u7b2c\u4e00\u4e2a\nprint(fruits&#91;-2])    # \u5012\u6570\u7b2c\u4e8c\u4e2a\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6a58\u5b50\n\u9999\u8549\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8d1f\u6570\u4e0b\u6807\u672c\u8d28\u662f\u300c\u957f\u5ea6 &#8211; \u6b63\u6570\u300d\u3002\u5217\u8868\u957f\u4e86\u4e4b\u540e\uff0c\u7528 <code>-1<\/code> \u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u662f\u6700\u9ad8\u9891\u7684\u5199\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>len() \u6570\u957f\u5ea6 + \u5b57\u7b26\u4e32\u4e5f\u80fd\u6309\u4e0b\u6807\u53d6<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits = &#91;\"\u82f9\u679c\", \"\u9999\u8549\", \"\u6a58\u5b50\"]\nprint(len(fruits))      # \u5217\u8868\u957f\u5ea6\nword = \"Python\"\nprint(word&#91;0])          # \u5b57\u7b26\u4e32\u4e5f\u80fd\u6309\u4e0b\u6807\u53d6\u5b57\u7b26\nprint(len(word))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3\nP\n6\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32\u672c\u8d28\u4e0a\u4e5f\u662f\u300c\u5b57\u7b26\u7684\u5e8f\u5217\u300d\uff0c\u540c\u6837\u652f\u6301\u4e0b\u6807\u3002\u8fd9\u4e5f\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48 Day 5 \u91cc <code>for ch in \"abc\"<\/code> \u80fd\u904d\u5386\u5b57\u7b26\u4e32\u2014\u2014\u51e1\u662f\u300c\u80fd\u6309\u4e0b\u6807\u53d6\u300d\u7684\u4e1c\u897f\u90fd\u80fd\u88ab for \u904d\u5386\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>fruits[3]<\/code>\uff08\u5217\u8868\u53ea\u6709 3 \u4e2a\u5143\u7d20\uff09 \u2192 \u95ee\u9898\uff1a\u62a5 <code>IndexError: list index out of range<\/code>\uff0c\u4e0b\u6807\u8d8a\u754c \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6700\u5927\u4e0b\u6807\u662f <code>len(\u5217\u8868) - 1<\/code>\uff0c\u6216\u7528\u8d1f\u6570\u4e0b\u6807 <code>[-1]<\/code> \u53d6\u6700\u540e\u4e00\u4e2a\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u4ee5\u4e3a\u4e0b\u6807\u4ece 1 \u5f00\u59cb\uff0c<code>fruits[1]<\/code> \u60f3\u53d6\u7b2c\u4e00\u4e2a \u2192 \u95ee\u9898\uff1a\u5b9e\u9645\u53d6\u5230\u7684\u662f\u7b2c\u4e8c\u4e2a\u5143\u7d20 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u7b2c n \u4e2a\u5143\u7d20\u7684\u4e0b\u6807\u662f n &#8211; 1\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>list = [1, 2]<\/code> \u7528 list \u5f53\u53d8\u91cf\u540d \u2192 \u95ee\u9898\uff1a\u8986\u76d6\u4e86\u5185\u7f6e\u51fd\u6570 <code>list()<\/code>\uff0c\u540e\u9762\u518d\u8c03\u7528 <code>list()<\/code> \u4f1a\u62a5\u9519 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u522b\u7528 <code>list<\/code>\u3001<code>str<\/code>\u3001<code>int<\/code> \u7b49\u5185\u7f6e\u540d\u5b57\u5f53\u53d8\u91cf\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u4e0b\u6807\u4ece\u96f6\u6570\uff0c-1 \u53d6\u672b\u5c3e\uff1b\u5185\u5b58\u8fde\u7eed\u5b58\uff0c\u53d6\u503c\u5feb\u5982\u98de\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 \u589e\u5220\u6539\u67e5 \u2014\u2014 \u52a8\u6001\u6570\u7ec4\u7684\u56db\u5927\u64cd\u4f5c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u80fd\u968f\u65f6\u589e\u3001\u5220\u3001\u6539\uff0c\u8fd9\u662f\u5b83\u6bd4\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u5f3a\u7684\u5730\u65b9\u3002\u4ee5\u540e\u5199\u7a0b\u5e8f\u5904\u7406\u6570\u636e\uff08\u52a0\u4e00\u6761\u8bb0\u5f55\u3001\u5220\u4e00\u6761\u8bb0\u5f55\u3001\u6539\u4e00\u4e2a\u503c\uff09\u5168\u9760\u8fd9\u51e0\u4e2a\u64cd\u4f5c\uff0c\u662f\u5217\u8868\u4f7f\u7528\u9891\u7387\u6700\u9ad8\u7684\u90e8\u5206\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a\u5217\u8868\u662f\u52a8\u6001\u6570\u7ec4\uff1a<code>append<\/code> \u5728\u672b\u5c3e\u8ffd\u52a0\u65f6\uff0c\u5bb9\u91cf\u591f\u5c31\u76f4\u63a5\u5199\uff1b\u5bb9\u91cf\u4e0d\u591f\u5c31\u300c\u642c\u5bb6\u300d\u2014\u2014\u91cd\u65b0\u7533\u8bf7\u4e00\u5757\u66f4\u5927\u7684\u5185\u5b58\uff08\u901a\u5e38\u662f\u539f\u5bb9\u91cf\u7684 1.125 \u500d\u6216\u66f4\u591a\uff09\uff0c\u628a\u65e7\u5143\u7d20\u590d\u5236\u8fc7\u53bb\u518d\u8ffd\u52a0\uff0c\u6240\u4ee5 append \u5076\u5c14\u6162\u4e00\u4e0b\uff0c\u4f46\u5e73\u5747\u5f88\u5feb\u3002<code>insert<\/code> \u63d2\u5230\u4e2d\u95f4\u5219\u8981\u628a\u63d2\u5165\u4f4d\u7f6e\u4e4b\u540e\u7684\u5143\u7d20<strong>\u5168\u90e8\u5f80\u540e\u632a\u4e00\u4f4d<\/strong>\uff0c\u5143\u7d20\u8d8a\u591a\u8d8a\u6162\u3002<code>remove<\/code> \u5220\u9664\u540c\u7406\uff1a\u5148\u627e\u5230\u503c\u7684\u4f4d\u7f6e\uff0c\u518d\u628a\u540e\u9762\u7684\u5143\u7d20\u5f80\u524d\u632a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u50cf\u4e00\u5217<strong>\u53ef\u6539\u9020\u7684\u706b\u8f66<\/strong>\uff1a<code>append<\/code> \u662f\u5728\u8f66\u5c3e\u6302\u4e00\u8282\u65b0\u8f66\u53a2\uff08\u6700\u7701\u4e8b\uff09\uff1b<code>insert<\/code> \u662f\u786c\u5728\u4e2d\u95f4\u63d2\u4e00\u8282\uff0c\u540e\u9762\u7684\u8f66\u53a2\u90fd\u5f97\u5f80\u540e\u632a\uff1b<code>remove<\/code> \/ <code>pop<\/code> \u662f\u5378\u6389\u4e00\u8282\u8f66\u53a2\uff0c\u540e\u9762\u7684\u518d\u5f80\u524d\u8865\u4f4d\u3002\u632a\u52a8\u8d8a\u591a\u8d8a\u6162\u2014\u2014\u6240\u4ee5\u8f66\u5c3e\u64cd\u4f5c\uff08append \/ pop \u672b\u5c3e\uff09\u603b\u662f\u6700\u5feb\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u589e\u2014\u2014append \u548c insert<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shopping = &#91;\"\u725b\u5976\"]\nshopping.append(\"\u9e21\u86cb\")      # \u672b\u5c3e\u8ffd\u52a0\nshopping.append(\"\u9762\u5305\")\nshopping.insert(1, \"\u706b\u817f\")   # \u63d2\u5230\u4e0b\u6807 1\nprint(shopping)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;'\u725b\u5976', '\u706b\u817f', '\u9e21\u86cb', '\u9762\u5305']\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>append(\u503c)<\/code> \u6c38\u8fdc\u628a\u65b0\u5143\u7d20\u653e\u5230\u6700\u540e\uff1b<code>insert(\u4f4d\u7f6e, \u503c)<\/code> \u628a\u503c\u63d2\u5230\u6307\u5b9a\u4e0b\u6807\uff0c\u539f\u672c\u8be5\u4f4d\u7f6e\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u81ea\u52a8\u5f80\u540e\u632a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u5220\u2014\u2014remove \u6309\u503c\u5220\uff0cpop \u6309\u4e0b\u6807\u5220<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;1, 2, 3, 4]\nnums.remove(2)          # \u6309\u300c\u503c\u300d\u5220\u9664\u7b2c\u4e00\u4e2a 2\nlast = nums.pop()       # \u5f39\u51fa\u6700\u540e\u4e00\u4e2a\nfirst = nums.pop(0)     # \u5f39\u51fa\u4e0b\u6807 0 \u7684\u5143\u7d20\nprint(nums)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;3]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>remove(\u503c)<\/code> \u6309\u503c\u5220\u9664\uff08\u53ea\u5220\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\uff0c\u503c\u4e0d\u5b58\u5728\u4f1a\u62a5 ValueError\uff09\uff1b<code>pop(\u4f4d\u7f6e)<\/code> \u5220\u9664\u5e76<strong>\u8fd4\u56de<\/strong>\u88ab\u5220\u7684\u503c\uff0c\u4e0d\u5199\u4f4d\u7f6e\u9ed8\u8ba4\u5f39\u6700\u540e\u4e00\u4e2a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>\u6539\u2014\u2014\u6309\u4e0b\u6807\u76f4\u63a5\u8d4b\u503c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scores = &#91;85, 92, 78]\nscores&#91;2] = 99          # \u628a\u7b2c\u4e09\u4e2a\u6210\u7ee9\u6539\u6210 99\nscores&#91;0] = scores&#91;0] + 10   # \u7b2c\u4e00\u4e2a\u6210\u7ee9\u52a0 10 \u518d\u5b58\u56de\u53bb\nprint(scores)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;95, 92, 99]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\u5217\u8868[\u4e0b\u6807] = \u65b0\u503c<\/code> \u662f\u300c\u6539\u300d\u7684\u552f\u4e00\u5199\u6cd5\u3002<code>scores[0] = scores[0] + 10<\/code> \u5148\u8bfb\u65e7\u503c\u3001\u52a0 10\u3001\u518d\u5199\u56de\u2014\u2014\u8fd9\u662f\u300c\u539f\u5730\u66f4\u65b0\u300d\u7684\u7ecf\u5178\u5199\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>nums.remove(99)<\/code>\uff0899 \u4e0d\u5728\u5217\u8868\u91cc\uff09 \u2192 \u95ee\u9898\uff1a\u62a5 <code>ValueError: x is not in list<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>if 99 in nums:<\/code> \u5224\u65ad\uff0c\u518d remove\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>shopping[5] = \"\u53ef\u4e50\"<\/code>\uff08\u60f3\u52a0\u65b0\u5143\u7d20\uff09 \u2192 \u95ee\u9898\uff1a\u62a5 <code>IndexError<\/code>\uff0c\u4e0b\u6807\u8d4b\u503c\u4e0d\u80fd\u8d8a\u754c\u65b0\u589e \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u8ffd\u52a0\u7528 <code>append<\/code>\uff0c\u63d2\u5165\u7528 <code>insert<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>nums.remove(2)<\/code> \u60f3\u5220\u6389<strong>\u6240\u6709<\/strong> 2 \u2192 \u95ee\u9898\uff1a\u53ea\u5220\u4e86\u7b2c\u4e00\u4e2a 2 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5faa\u73af remove \u76f4\u5230 <code>2 not in nums<\/code>\uff0c\u6216\u7528\u5217\u8868\u63a8\u5bfc\uff08Day 8 \u540e\u5b66\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>fruits = fruits.append(\"\u68a8\")<\/code> \u2192 \u95ee\u9898\uff1a\u628a append \u7684\u8fd4\u56de\u503c\u8d4b\u7ed9\u53d8\u91cf\uff0cfruits \u53d8\u6210 None\uff01 \u2192 \u6b63\u786e\u5199\u6cd5\uff1aappend \u662f\u300c\u539f\u5730\u64cd\u4f5c\u300d\uff0c\u8fd4\u56de None\uff0c\u76f4\u63a5 <code>fruits.append(\"\u68a8\")<\/code> \u5373\u53ef\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u672b\u5c3e\u8ffd\u52a0 append\uff0c\u6307\u5b9a\u4f4d\u7f6e insert\uff1b\u6309\u503c\u5220\u9664 remove\uff0c\u5f39\u51fa\u7528 pop \u6709\u56de\u793c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 \u5207\u7247 \u2014\u2014 \u4e00\u6b21\u53d6\u51fa\u4e00\u6bb5\u6570\u636e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5207\u7247<\/strong>\uff08slicing\uff09\u7528 <code>\u5217\u8868[\u5f00\u59cb:\u7ed3\u675f:\u6b65\u957f]<\/code> \u4e00\u6b21\u53d6\u51fa\u4e00\u6bb5\uff0c\u662f Python \u6700\u4f18\u96c5\u7684\u8bed\u6cd5\u4e4b\u4e00\u3002\u53cd\u8f6c\u3001\u53d6\u524d\u4e09\u4e2a\u3001\u9694\u4e00\u4e2a\u53d6\u4e00\u4e2a\u2026\u2026\u4e00\u884c\u641e\u5b9a\u3002\u5b66\u4f1a\u5207\u7247\uff0c\u5f88\u591a\u770b\u4f3c\u590d\u6742\u7684\u64cd\u4f5c\u4f1a\u53d8\u6210\u4e00\u884c\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5207\u7247\u64cd\u4f5c\u4f1a<strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u8868<\/strong>\uff08\u62f7\u8d1d\uff09\uff1aPython \u6309\u4f60\u7ed9\u7684\u5f00\u59cb\u3001\u7ed3\u675f\u3001\u6b65\u957f\uff0c\u628a\u5bf9\u5e94\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u5217\u8868\u91cc\u3002\u6240\u4ee5\u5207\u51fa\u6765\u7684\u5217\u8868\u548c\u539f\u5217\u8868\u662f\u300c\u4e24\u4efd\u72ec\u7acb\u7684\u6570\u636e\u300d\u2014\u2014\u4fee\u6539\u5207\u7247\u7ed3\u679c\u4e0d\u4f1a\u5f71\u54cd\u539f\u5217\u8868\u3002\u6b65\u957f\u4e3a\u8d1f\u65f6\uff0cPython \u4ece\u5c3e\u90e8\u53cd\u5411\u53d6\uff0c<code>[::-1]<\/code> \u56e0\u6b64\u6210\u4e86\u300c\u53cd\u8f6c\u300d\u7684\u7ecf\u5178\u5199\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5207\u7247\u50cf<strong>\u590d\u5370\u673a<\/strong>\uff1a\u4f60\u4ece\u4e00\u645e\u8d44\u6599\u91cc\u9009\u51fa\u7b2c 3~5 \u5f20\uff0c\u590d\u5370\u51fa\u4e00\u4efd\u65b0\u7684\u5c0f\u518c\u5b50\u2014\u2014\u539f\u8d44\u6599\u4e00\u52a8\u4e0d\u52a8\uff0c\u590d\u5370\u4ef6\u968f\u4fbf\u6539\u3002<code>[:]<\/code> \u5c31\u662f\u300c\u6574\u645e\u5168\u90e8\u590d\u5370\u4e00\u904d\u300d\uff0c<code>[::-1]<\/code> \u662f\u300c\u5012\u7740\u590d\u5370\u4e00\u904d\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u57fa\u672c\u5207\u7247\u2014\u2014\u542b\u5934\u4e0d\u542b\u5c3e<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;10, 20, 30, 40, 50]\nprint(nums&#91;1:4])     # \u4e0b\u6807 1 \u5230 3\nprint(nums&#91;:3])      # \u4ece\u5934\u5230\u4e0b\u6807 2\nprint(nums&#91;2:])      # \u4ece\u4e0b\u6807 2 \u5230\u672b\u5c3e\nprint(nums&#91;:])       # \u6574\u4e2a\u62f7\u8d1d\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;20, 30, 40]\n&#91;10, 20, 30]\n&#91;30, 40, 50]\n&#91;10, 20, 30, 40, 50]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>[1:4]<\/code> \u53d6\u4e0b\u6807 1\u30012\u30013\uff08\u542b 1 \u4e0d\u542b 4\uff09\uff0c\u548c range \u4e00\u6837\u300c\u542b\u5934\u4e0d\u542b\u5c3e\u300d\uff1b\u7701\u7565\u5f00\u59cb = \u4ece\u5934\u5f00\u59cb\uff1b\u7701\u7565\u7ed3\u675f = \u5230\u672b\u5c3e\uff1b<code>[:]<\/code> \u90fd\u7701\u7565 = \u6574\u4e2a\u5217\u8868\u7684\u62f7\u8d1d\uff08\u4e0d\u662f\u540c\u4e00\u4e2a\u5217\u8868\uff01\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u6b65\u957f\u2014\u2014\u9694\u4e00\u4e2a\u53d6\u4e00\u4e2a\u3001\u53cd\u8f6c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;10, 20, 30, 40, 50]\nprint(nums&#91;::2])     # \u9694\u4e00\u4e2a\u53d6\u4e00\u4e2a\nprint(nums&#91;::-1])    # \u53cd\u8f6c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;10, 30, 50]\n&#91;50, 40, 30, 20, 10]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>[::2]<\/code> \u6b65\u957f\u4e3a 2\uff0c\u53d6\u4e0b\u6807 0\u30012\u30014\uff1b<code>[::-1]<\/code> \u6b65\u957f\u4e3a -1\uff0c\u4ece\u5c3e\u90e8\u5f00\u59cb\u6bcf\u6b21\u51cf 1\uff0c\u7ed3\u679c\u5c31\u662f\u53cd\u8f6c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>\u5207\u7247\u4ea7\u751f\u7684\u662f\u65b0\u5217\u8868\uff08\u4fee\u6539\u5207\u7247\u4e0d\u5f71\u54cd\u539f\u5217\u8868\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;1, 2, 3, 4, 5]\npart = nums&#91;1:3]\npart&#91;0] = 99\nprint(part)          # \u4fee\u6539\u5207\u7247\u7ed3\u679c\nprint(nums)          # \u539f\u5217\u8868\u4e0d\u53d7\u5f71\u54cd\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;99, 3]\n&#91;1, 2, 3, 4, 5]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6539 part \u53ea\u662f\u6539\u90a3\u4efd\u62f7\u8d1d\uff0cnums \u8fd8\u662f\u539f\u6837\u3002\u7406\u89e3\u8fd9\u4e00\u70b9\uff0c\u4f60\u5c31\u4e0d\u4f1a\u72af\u300c\u6539\u5207\u7247\u4ee5\u4e3a\u6539\u4e86\u539f\u5217\u8868\u300d\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>nums[1:4]<\/code> \u4ee5\u4e3a\u53d6 4 \u4e2a \u2192 \u95ee\u9898\uff1a\u53ea\u53d6 3 \u4e2a\uff08\u4e0b\u6807 1\u30012\u30013\uff09 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u8bb0\u4f4f\u542b\u5934\u4e0d\u542b\u5c3e\uff1a\u4e2a\u6570 = \u7ed3\u675f &#8211; \u5f00\u59cb\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u60f3\u53cd\u8f6c\u5374\u5199 <code>nums[-1]<\/code> \u2192 \u95ee\u9898\uff1a<code>nums[-1]<\/code> \u53ea\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u4e0d\u662f\u53cd\u8f6c \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u53cd\u8f6c\u5199 <code>nums[::-1]<\/code>\uff0c<code>nums[-1]<\/code> \u662f\u53d6\u672b\u5c3e\u5355\u4e2a\u5143\u7d20\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5207\u7247\u7684\u5f00\u59cb\u6bd4\u7ed3\u675f\u5927\uff08\u6b63\u6b65\u957f\uff0c\u5982 <code>nums[4:1]<\/code>\uff09 \u2192 \u95ee\u9898\uff1a\u8fd4\u56de\u7a7a\u5217\u8868 <code>[]<\/code>\uff0c\u4e0d\u62a5\u9519\u4f46\u7ed3\u679c\u4e0d\u662f\u60f3\u8981\u7684 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u4ece\u540e\u5f80\u524d\u53d6\u8981\u7528\u8d1f\u6b65\u957f\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u4ee5\u4e3a\u5207\u7247\u4f1a\u4fee\u6539\u539f\u5217\u8868 \u2192 \u95ee\u9898\uff1a\u5207\u7247\u6c38\u8fdc\u8fd4\u56de\u65b0\u5217\u8868\uff0c\u539f\u5217\u8868\u4e0d\u53d8 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u539f\u5730\u6539\u539f\u5217\u8868\u7528\u8d4b\u503c\uff1a<code>nums[:2] = [0, 0]<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u5207\u7247\u4e09\u53c2\u6570\uff0c\u542b\u5934\u4e0d\u542b\u5c3e\uff1b\u8d1f\u53f7\u4e00\u51fa\u73b0\uff0c\u65b9\u5411\u5c31\u53cd\u8f6c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4 \u5143\u7ec4 \u2014\u2014 \u4e3a\u4ec0\u4e48\u9700\u8981\u300c\u4e0d\u53ef\u53d8\u300d\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5143\u7ec4<\/strong>\uff08tuple\uff09\u7528\u5706\u62ec\u53f7\uff0c\u957f\u5f97\u50cf\u5217\u8868\uff0c\u4f46\u521b\u5efa\u540e<strong>\u4e0d\u80fd\u589e\u5220\u6539<\/strong>\u3002\u542c\u8d77\u6765\u5f88\u6ca1\u7528\uff1f\u6070\u6070\u76f8\u53cd\uff1a\u6b63\u56e0\u4e3a\u4e0d\u53ef\u53d8\uff0c\u5143\u7ec4\u624d\u80fd\u5f53\u5b57\u5178\u7684\u952e\u3001\u624d\u80fd\u5b89\u5168\u5730\u5230\u5904\u4f20\u9012\u4e0d\u88ab\u610f\u5916\u4fee\u6539\uff0c\u8fd0\u884c\u901f\u5ea6\u8fd8\u66f4\u5feb\u3002\u5b83\u662f Python \u91cc\u300c\u56fa\u5b9a\u6570\u636e\u300d\u7684\u4e13\u7528\u5bb9\u5668\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5143\u7ec4\u5728\u5185\u5b58\u91cc\u662f<strong>\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4<\/strong>\uff1a\u521b\u5efa\u65f6\u4e00\u6b21\u6027\u5206\u914d\u597d\u6240\u6709\u5143\u7d20\u7684\u7a7a\u95f4\uff0c\u4e4b\u540e\u7ed3\u6784\u4e0d\u518d\u53d8\u5316\uff0c\u6240\u4ee5\u5143\u7ec4\u6ca1\u6709 append\/remove \u8fd9\u4e9b\u65b9\u6cd5\u3002\u4e5f\u6b63\u56e0\u4e3a\u7ed3\u6784\u56fa\u5b9a\uff0cPython \u80fd\u505a\u66f4\u591a\u4f18\u5316\uff08\u66f4\u5c11\u5185\u5b58\u3001\u66f4\u5feb\u7684\u8bbf\u95ee\uff09\uff0c\u8fd8\u80fd\u7b97\u51fa\u56fa\u5b9a\u7684\u300c\u54c8\u5e0c\u503c\u300d\u2014\u2014\u8fd9\u662f\u5b83\u4ee5\u540e\u80fd\u5f53\u5b57\u5178\u952e\u7684\u6839\u672c\u539f\u56e0\uff08Day 7 \u4f1a\u5b66\uff09\u3002\u5217\u8868\u53ef\u53d8\uff0c\u7b97\u4e0d\u51fa\u7a33\u5b9a\u7684\u54c8\u5e0c\uff0c\u6240\u4ee5\u5217\u8868\u4e0d\u80fd\u5f53\u5b57\u5178\u952e\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u672f\u8bed\u5c0f\u8bcd\u5178\uff1a<strong>\u54c8\u5e0c\u503c<\/strong>\uff08hash value\uff09\u5c31\u662f\u7ed9\u6bcf\u4e2a\u952e\u7b97\u4e00\u4e2a\u7c7b\u4f3c\u300c\u7d22\u5f15\u7f16\u53f7\u300d\u7684\u6570\u5b57\uff0c\u6309\u7f16\u53f7\u76f4\u63a5\u5b9a\u4f4d\uff0c\u67e5\u8d77\u6765\u98de\u5feb\u2014\u2014\u5c31\u50cf\u56fe\u4e66\u9986\u6309\u4e66\u53f7\u627e\u4e66\uff0c\u800c\u4e0d\u662f\u4e00\u672c\u672c\u7ffb\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5143\u7ec4\u50cf<strong>\u5851\u5c01\u7684\u8bc1\u4ef6\u7167<\/strong>\uff1a\u7167\u7247\u5b9a\u597d\u540e\u5c31\u4e0d\u80fd\u518d\u6539\uff08\u4e0d\u53ef\u53d8\uff09\uff0c\u6b63\u56e0\u4e3a\u4e0d\u4f1a\u53d8\uff0c\u624d\u80fd\u653e\u5fc3\u5730\u5230\u5904\u63d0\u4ea4\uff08\u5f53\u5b57\u5178\u952e\u3001\u5b89\u5168\u4f20\u9012\uff09\uff1b\u5217\u8868\u50cf\u666e\u901a\u7167\u7247\uff0c\u968f\u65f6\u80fd\u6d82\u6539\uff0c\u53cd\u800c\u4e0d\u9002\u5408\u5f53\u300c\u8eab\u4efd\u8bc1\u660e\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u521b\u5efa\u548c\u8bfb\u53d6\u5143\u7ec4 + \u62c6\u5305<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>point = (3, 5)          # \u4e00\u4e2a\u5750\u6807\u70b9\nprint(point&#91;0])         # \u6309\u4e0b\u6807\u53d6\nx, y = point            # \u62c6\u5305\uff1a\u4e00\u6b21\u6027\u53d6\u51fa\u6240\u6709\u503c\nprint(\"x =\", x, \"y =\", y)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3\nx = 3 y = 5\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>x, y = point<\/code> \u662f\u5143\u7ec4\u4e13\u5c5e\u7684\u300c\u62c6\u5305\u300d\u8bed\u6cd5\u2014\u2014\u5de6\u8fb9\u5199\u51e0\u4e2a\u53d8\u91cf\uff0c\u53f3\u8fb9\u5143\u7ec4\u6709\u51e0\u4e2a\u5143\u7d20\uff0c\u81ea\u52a8\u4e00\u4e00\u5bf9\u5e94\u8d4b\u503c\u3002Day 7 \u904d\u5386\u5b57\u5178\u65f6\u8fd8\u4f1a\u89c1\u5230\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u5143\u7ec4\u4e0d\u80fd\u4fee\u6539\uff08\u9519\u8bef\u793a\u8303\uff0c\u8fd0\u884c\u4f1a\u62a5\u9519\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>point = (3, 5)\n# point&#91;0] = 100   # \u8fd0\u884c\u4f1a\u62a5\u9519\uff1aTypeError: 'tuple' object does not support item assignment\nprint(\"\u5143\u7ec4\u4e00\u65e6\u521b\u5efa\uff0c\u5185\u5bb9\u5c31\u56fa\u5b9a\u4e86\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u300c\u4e0d\u53ef\u53d8\u300d\u6307\u7684\u662f\u7ed3\u6784\u4e0d\u53ef\u53d8\uff1a\u5143\u7ec4\u91cc\u7684<strong>\u4f4d\u7f6e\u548c\u4e2a\u6570<\/strong>\u56fa\u5b9a\u4e86\uff0c\u4f46\u5143\u7d20\u672c\u8eab\u5982\u679c\u662f\u53ef\u53d8\u7c7b\u578b\uff08\u5982\u5217\u8868\uff09\u4ecd\u7136\u53ef\u4ee5\u6539\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>\u5143\u7ec4\u7684\u4e24\u79cd\u521b\u5efa\u59ff\u52bf\uff08\u4e00\u4e2a\u5c0f\u9677\u9631\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>t1 = (1, 2, 3)          # \u6b63\u5e38\u5143\u7ec4\nt2 = (1)                # \u6ca1\u6709\u9017\u53f7\uff01\u8fd9\u662f\u6574\u6570\u4e0d\u662f\u5143\u7ec4\nt3 = (1,)               # \u52a0\u9017\u53f7\u624d\u662f\u5143\u7ec4\nprint(type(t1))\nprint(type(t2))\nprint(type(t3))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;class 'tuple'&gt;\n&lt;class 'int'&gt;\n&lt;class 'tuple'&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>(1)<\/code> \u91cc\u6ca1\u6709\u9017\u53f7\uff0cPython \u628a\u5b83\u5f53\u6210\u6570\u5b66\u91cc\u7684\u62ec\u53f7\uff0c\u7ed3\u679c\u662f\u6574\u6570 1\uff1b\u521b\u5efa\u5355\u5143\u7d20\u5143\u7ec4\u5fc5\u987b\u5199 <code>(1,)<\/code>\u2014\u2014\u8fd9\u4e2a\u9017\u53f7\u662f\u5143\u7ec4\u7684\u300c\u8eab\u4efd\u6807\u8bc6\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>point[0] = 100<\/code> \u2192 \u95ee\u9898\uff1a\u62a5 <code>TypeError<\/code>\uff0c\u5143\u7ec4\u4e0d\u80fd\u6539 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u7528\u5217\u8868\uff1b\u6216\u91cd\u65b0\u521b\u5efa\u5143\u7ec4 <code>point = (100, 5)<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>t = (1)<\/code> \u60f3\u521b\u5efa\u5355\u5143\u7d20\u5143\u7ec4 \u2192 \u95ee\u9898\uff1at \u5176\u5b9e\u662f\u6574\u6570 1 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5199 <code>t = (1,)<\/code>\uff0c\u9017\u53f7\u4e0d\u80fd\u7701\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u8bd5\u56fe <code>tuple.append(1)<\/code> \u2192 \u95ee\u9898\uff1a\u62a5 <code>AttributeError<\/code>\uff0c\u5143\u7ec4\u6ca1\u6709 append \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5143\u7ec4\u521b\u5efa\u540e\u4e0d\u80fd\u52a0\u5143\u7d20\uff0c\u9700\u8981\u53d8\u957f\u5c31\u7528\u5217\u8868\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5fd8\u8bb0\u5143\u7ec4\u80fd\u62c6\u5305\uff0c\u5199\u4e09\u884c\u5206\u522b\u53d6 \u2192 \u95ee\u9898\uff1a\u4ee3\u7801\u5570\u55e6 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>x, y, z = (1, 2, 3)<\/code> \u4e00\u884c\u641e\u5b9a\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u5143\u7ec4\u5706\u62ec\u53f7\uff0c\u51fa\u751f\u5b9a\u7ec8\u8eab\uff1b\u60f3\u53d6\u5168\u51fa\u6765\uff0c\u62c6\u5305\u4e00\u884c\u6210\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5 \u904d\u5386\u5217\u8868\u4e0e\u5e38\u7528\u65b9\u6cd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a\u5217\u8868\u91cc\u7684\u5143\u7d20\u300c\u4e00\u4e2a\u4e00\u4e2a\u300d\u62ff\u51fa\u6765\u5904\u7406\uff0c\u5c31\u662f<strong>\u904d\u5386<\/strong>\u3002\u7ed3\u5408 Day 5 \u7684 for \u5faa\u73af\uff0c\u5c31\u80fd\u5904\u7406\u6210\u767e\u4e0a\u5343\u6761\u6570\u636e\uff08\u6c42\u548c\u3001\u7edf\u8ba1\u3001\u7b5b\u9009\uff09\u3002\u8fd9\u662f\u300c\u5bb9\u5668 + \u5faa\u73af\u300d\u7684\u7ec4\u5408\u62f3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u904d\u5386 + enumerate \u540c\u65f6\u62ff\u4e0b\u6807 + \u6c42\u548c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scores = &#91;85, 92, 78]\nfor score in scores:                 # \u76f4\u63a5\u904d\u5386\u5143\u7d20\n    print(\"\u6210\u7ee9\uff1a\", score)\nfor index, score in enumerate(scores):   # \u8fd8\u9700\u8981\u4f4d\u7f6e\u4fe1\u606f\u65f6\u7528 enumerate\n    print(\"\u7b2c\", index + 1, \"\u4e2a\u6210\u7ee9\u662f\", score)\ntotal = 0\nfor score in scores:                 # \u7d2f\u52a0\u5668\uff08Day 5 \u7684\u5347\u7ea7\u7248\uff09\n    total = total + score\nprint(\"\u603b\u5206\uff1a\", total, \"\u5e73\u5747\u5206\uff1a\", total \/ len(scores))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6210\u7ee9\uff1a 85\n\u6210\u7ee9\uff1a 92\n\u6210\u7ee9\uff1a 78\n\u7b2c 1 \u4e2a\u6210\u7ee9\u662f 85\n\u7b2c 2 \u4e2a\u6210\u7ee9\u662f 92\n\u7b2c 3 \u4e2a\u6210\u7ee9\u662f 78\n\u603b\u5206\uff1a 255 \u5e73\u5747\u5206\uff1a 85.0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u5173\u5fc3\u300c\u6bcf\u4e2a\u503c\u300d\u7528 <code>for x in \u5217\u8868<\/code>\uff1b\u8fd8\u9700\u8981\u300c\u7b2c\u51e0\u4e2a\u300d\u7684\u4f4d\u7f6e\u4fe1\u606f\u65f6\u7528 <code>enumerate<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u5e38\u7528\u65b9\u6cd5\u901f\u67e5\u8868<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6cd5<\/th><th>\u4f5c\u7528<\/th><\/tr><\/thead><tbody><tr><td><code>\u5217\u8868.sort()<\/code><\/td><td>\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff08\u4f1a\u6539\u53d8\u539f\u5217\u8868\uff09<\/td><\/tr><tr><td><code>\u5217\u8868.reverse()<\/code><\/td><td>\u53cd\u8f6c\u987a\u5e8f\uff08\u4f1a\u6539\u53d8\u539f\u5217\u8868\uff09<\/td><\/tr><tr><td><code>\u5217\u8868.index(\u503c)<\/code><\/td><td>\u67e5\u627e\u503c\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4e0b\u6807<\/td><\/tr><tr><td><code>\u5217\u8868.count(\u503c)<\/code><\/td><td>\u7edf\u8ba1\u503c\u51fa\u73b0\u6b21\u6570<\/td><\/tr><tr><td><code>\u503c in \u5217\u8868<\/code><\/td><td>\u5224\u65ad\u503c\u5728\u4e0d\u5728\u5217\u8868\u91cc\uff08\u8fd4\u56de True\/False\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;5, 2, 8, 1]\nnums.sort()          # \u4ece\u5c0f\u5230\u5927\nprint(nums)          # &#91;1, 2, 5, 8]\nnums.sort(reverse=True)  # \u4ece\u5927\u5230\u5c0f\nprint(nums)          # &#91;8, 5, 2, 1]\n\nnums2 = &#91;3, 7, 3, 9, 3]\nprint(nums2.index(7))   # 7 \u7684\u4e0b\u6807\u662f 1\nprint(nums2.count(3))   # 3 \u51fa\u73b0\u4e86 3 \u6b21\nprint(9 in nums2)       # True\nprint(5 in nums2)       # False\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u904d\u5386\u65f6\u60f3\u6539\u5217\u8868\u5143\u7d20\u5374\u76f4\u63a5 <code>for x in \u5217\u8868: x = \u65b0\u503c<\/code> \u2192 \u95ee\u9898\uff1ax \u53ea\u662f\u5143\u7d20\u7684\u62f7\u8d1d\uff0c\u6539\u4e86\u4e0d\u5f71\u54cd\u539f\u5217\u8868 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u7528\u4e0b\u6807 <code>for i in range(len(\u5217\u8868)): \u5217\u8868[i] = \u65b0\u503c<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>sort()<\/code> \u548c <code>sorted()<\/code> \u5206\u4e0d\u6e05 \u2192 \u95ee\u9898\uff1a<code>sort()<\/code> \u539f\u5730\u6539\u5e76\u8fd4\u56de None\uff0c<code>sorted()<\/code> \u8fd4\u56de\u65b0\u5217\u8868 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u4fdd\u7559\u539f\u5217\u8868\u7528 <code>sorted(\u5217\u8868)<\/code>\uff0c\u60f3\u539f\u5730\u6392\u7528 <code>\u5217\u8868.sort()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u904d\u5386\u7528 for\uff0c\u4f4d\u7f6e\u7528 enumerate\uff1b\u6392\u5e8f\u539f\u5730 sort\uff0c\u7edf\u8ba1 count \u548c in\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6 \u52a8\u624b\u5b9e\u8df5\uff1a\u8d2d\u7269\u6e05\u5355\u7ba1\u7406<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u505a\u4e00\u4e2a\u8d2d\u7269\u6e05\u5355\u7ba1\u7406\u7a0b\u5e8f\uff0c\u652f\u6301 4 \u4e2a\u529f\u80fd\uff1a\u67e5\u770b\u6e05\u5355\u3001\u6dfb\u52a0\u7269\u54c1\u3001\u5220\u9664\u7269\u54c1\u3001\u9000\u51fa\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8d2d\u7269\u6e05\u5355\u7ba1\u7406\nshopping = &#91;\"\u725b\u5976\", \"\u9e21\u86cb\", \"\u9762\u5305\"]\n\nwhile True:\n    print(\"\\n\u5f53\u524d\u6e05\u5355\uff1a\", shopping)\n    print(\"1. \u67e5\u770b\u6e05\u5355  2. \u6dfb\u52a0\u7269\u54c1  3. \u5220\u9664\u7269\u54c1  4. \u9000\u51fa\")\n    choice = input(\"\u8bf7\u9009\u62e9\u64cd\u4f5c\uff1a\")\n\n    if choice == \"1\":\n        if len(shopping) == 0:\n            print(\"\u6e05\u5355\u662f\u7a7a\u7684\")\n        else:\n            for i, item in enumerate(shopping):\n                print(i + 1, \". \", item)\n\n    elif choice == \"2\":\n        item = input(\"\u8981\u6dfb\u52a0\u4ec0\u4e48\uff1a\")\n        shopping.append(item)\n        print(\"\u5df2\u6dfb\u52a0\uff1a\", item)\n\n    elif choice == \"3\":\n        item = input(\"\u8981\u5220\u9664\u4ec0\u4e48\uff08\u8f93\u5165\u7269\u54c1\u540d\uff09\uff1a\")\n        if item in shopping:\n            shopping.remove(item)\n            print(\"\u5df2\u5220\u9664\uff1a\", item)\n        else:\n            print(\"\u6e05\u5355\u91cc\u6ca1\u6709\u8fd9\u4e2a\u4e1c\u897f\")\n\n    elif choice == \"4\":\n        print(\"\u518d\u89c1\uff01\")\n        break\n\n    else:\n        print(\"\u65e0\u6548\u9009\u9879\uff0c\u8bf7\u8f93\u5165 1~4\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bd5\u7740\u8fd0\u884c\uff1a\u6dfb\u52a0\u300c\u53ef\u4e50\u300d\u3001\u5220\u9664\u300c\u9e21\u86cb\u300d\u3001\u8f93\u5165\u65e0\u6548\u9009\u9879\uff0c\u89c2\u5bdf\u7a0b\u5e8f\u7684\u8868\u73b0\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u628a Day 4 \u7684 if\/elif\u3001Day 5 \u7684 while\/break\u3001Day 6 \u7684\u5217\u8868\u589e\u5220\u6539\u67e5\u5168\u90e8\u4e32\u8d77\u6765\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u662f\u4ec0\u4e48\uff1a\u5185\u5b58\u91cc\u7684\u300c\u52a8\u6001\u6570\u7ec4\u300d\uff0c\u5b58\u7684\u662f\u5f15\u7528\u6240\u4ee5\u80fd\u6df7\u88c5\u7c7b\u578b\uff0c\u6309\u4e0b\u6807\u53d6\u503c\u6781\u5feb\n\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c<code>-1<\/code> \u662f\u6700\u540e\u4e00\u4e2a\uff0c\u6700\u5927\u4e0b\u6807\u662f <code>len(\u5217\u8868) - 1<\/code>\n\u589e\uff1a<code>append<\/code>\uff08\u672b\u5c3e\uff09\/ <code>insert<\/code>\uff08\u6307\u5b9a\u4f4d\u7f6e\uff09\uff1b\u5220\uff1a<code>remove<\/code>\uff08\u6309\u503c\uff09\/ <code>pop<\/code>\uff08\u6309\u4f4d\u7f6e\u5e76\u8fd4\u56de\uff09\n\u6539\uff1a<code>\u5217\u8868[\u4e0b\u6807] = \u65b0\u503c<\/code>\uff1b<code>append<\/code> \/ <code>sort<\/code> \/ <code>reverse<\/code> \u90fd\u662f\u539f\u5730\u64cd\u4f5c\uff0c\u8fd4\u56de None\n\u5207\u7247 <code>\u5217\u8868[\u5f00\u59cb:\u7ed3\u675f:\u6b65\u957f]<\/code> \u542b\u5934\u4e0d\u542b\u5c3e\u3001\u8fd4\u56de\u65b0\u5217\u8868\uff1b<code>[::-1]<\/code> \u53cd\u8f6c\n\u904d\u5386\uff1a<code>for x in \u5217\u8868<\/code> \u53d6\u5143\u7d20\uff0c<code>enumerate<\/code> \u540c\u65f6\u62ff\u4e0b\u6807\uff0c\u914d\u5408\u7d2f\u52a0\u5668\u505a\u7edf\u8ba1\n\u5143\u7ec4\u7528 <code>()<\/code>\uff0c\u4e0d\u53ef\u53d8\u3001\u53ef\u62c6\u5305\u3001\u66f4\u5feb\uff1b\u5355\u5143\u7d20\u5143\u7ec4\u5fc5\u987b\u5e26\u9017\u53f7 <code>(1,)<\/code>\n\u5b8c\u6210\u8d2d\u7269\u6e05\u5355\u7ba1\u7406\u5e76\u6d4b\u8bd5\u6dfb\u52a0\u3001\u5220\u9664\u3001\u65e0\u6548\u8f93\u5165\u4e09\u79cd\u573a\u666f<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u62a5\u9519<\/th><th>\u539f\u56e0<\/th><th>\u4fee\u590d<\/th><\/tr><\/thead><tbody><tr><td><code>IndexError: list index out of range<\/code><\/td><td>\u4e0b\u6807\u8d85\u51fa\u4e86\u5217\u8868\u957f\u5ea6<\/td><td>\u68c0\u67e5\u4e0b\u6807\u8303\u56f4\uff0c\u6700\u5927\u4e0b\u6807\u662f <code>len(\u5217\u8868) - 1<\/code><\/td><\/tr><tr><td><code>ValueError: x is not in list<\/code><\/td><td><code>remove<\/code> \/ <code>index<\/code> \u7684\u503c\u5728\u5217\u8868\u91cc\u4e0d\u5b58\u5728<\/td><td>\u5148\u5224\u65ad <code>if \u503c in \u5217\u8868<\/code> \u518d\u5220\u9664\u6216\u67e5\u627e<\/td><\/tr><tr><td><code>TypeError: 'tuple' object does not support item assignment<\/code><\/td><td>\u8bd5\u56fe\u4fee\u6539\u5143\u7ec4<\/td><td>\u5143\u7ec4\u4e0d\u53ef\u53d8\uff0c\u6539\u7528\u5217\u8868\u6216\u91cd\u65b0\u521b\u5efa\u5143\u7ec4<\/td><\/tr><tr><td><code>AttributeError: 'list' object has no attribute 'append'<\/code><\/td><td>\u628a\u53d8\u91cf\u540d\u62fc\u9519\uff0c\u6216\u5bf9\u975e\u5217\u8868\u8c03\u7528\u4e86 append<\/td><td>\u786e\u8ba4\u53d8\u91cf\u771f\u7684\u662f\u5217\u8868\uff0c\u68c0\u67e5\u62fc\u5199<\/td><\/tr><tr><td><code>TypeError: 'int' object is not subscriptable<\/code><\/td><td>\u5bf9\u6570\u5b57\u7528\u4e86\u4e0b\u6807\uff08<code>5[0]<\/code>\uff09<\/td><td>\u4e0b\u6807\u53ea\u80fd\u7528\u5728\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u4e0a<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1 \u5217\u8868\u7684\u5e95\u5c42 \u2014\u2014 \u5185\u5b58\u4e2d\u7684\u8fde\u7eed\u8f66\u53a2 \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f \u5217\u8868\uff08list\uff09\u662f Python \u91cc\u6700\u5e38\u7528\u7684\u5bb9\u5668\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[16,9],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-python","category-code-dev"],"_links":{"self":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":2,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/135"}],"wp:attachment":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}