{"id":52413,"date":"2025-08-11T14:19:36","date_gmt":"2025-08-11T06:19:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/52413.html"},"modified":"2025-08-11T14:19:36","modified_gmt":"2025-08-11T06:19:36","slug":"%e4%b8%80%e6%96%87%e5%90%83%e9%80%8f-python-%e5%88%97%e8%a1%a8%e3%80%81%e5%ad%97%e5%85%b8%e3%80%81%e5%85%83%e7%bb%84%e5%92%8c%e9%9b%86%e5%90%88%ef%bc%8c%e6%96%b0%e6%89%8b%e5%bf%85%e7%9c%8b%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/52413.html","title":{"rendered":"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01"},"content":{"rendered":"<h4 id=\"%E4%B8%80%E3%80%81%E5%88%97%E8%A1%A8%EF%BC%88List%EF%BC%89\">\u4e00\u3001\u5217\u8868&#xff08;List&#xff09;<\/h4>\n<h5 id=\"1.%20%E5%AE%9A%E4%B9%89%E4%B8%8E%E8%A1%A8%E7%A4%BA\">1. \u5b9a\u4e49\u4e0e\u8868\u793a<\/h5>\n<ul>\n<li>\u5217\u8868\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6709\u5e8f\u3001\u53ef\u53d8\u6570\u636e\u7c7b\u578b&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4e00\u7cfb\u5217\u5143\u7d20&#xff08;\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u636e\u7c7b\u578b&#xff0c;\u5305\u62ec\u5d4c\u5957\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u3001\u5143\u7ec4\u7b49&#xff09;\u3002<\/li>\n<li>\u8868\u793a\u65b9\u5f0f&#xff1a;\u7528\u00a0[]\u00a0\u5305\u88f9\u5143\u7d20&#xff0c;\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694&#xff0c;\u4f8b\u5982&#xff1a;\n<p>list1 &#061; [1, 2, 3]  # \u6574\u6570\u5217\u8868<br \/>\nlist2 &#061; [&#034;a&#034;, 1, True, [4, 5]]  # \u6df7\u5408\u7c7b\u578b\u5217\u8868&#xff08;\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u3001\u5d4c\u5957\u5217\u8868&#xff09;<br \/>\nempty_list &#061; []  # \u7a7a\u5217\u8868<\/p>\n<\/li>\n<\/ul>\n<h5 id=\"2.%20%E6%A0%B8%E5%BF%83%E7%89%B9%E6%80%A7\">2. \u6838\u5fc3\u7279\u6027<\/h5>\n<ul>\n<li>\u6709\u5e8f\u6027&#xff1a;\u5143\u7d20\u6709\u56fa\u5b9a\u987a\u5e8f&#xff0c;\u53ef\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee&#xff08;\u7d22\u5f15\u4ece 0 \u5f00\u59cb&#xff09;\u3002<\/li>\n<li>\u53ef\u53d8\u6027&#xff1a;\u53ef\u4fee\u6539\u3001\u6dfb\u52a0\u3001\u5220\u9664\u5143\u7d20&#xff08;\u5185\u5b58\u5730\u5740\u4e0d\u53d8&#xff0c;\u5185\u5bb9\u53ef\u53d8&#xff09;\u3002<\/li>\n<li>\u53ef\u91cd\u590d\u6027&#xff1a;\u5141\u8bb8\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002<\/li>\n<li>\u5f02\u6784\u6027&#xff1a;\u5143\u7d20\u53ef\u4ee5\u662f\u4e0d\u540c\u6570\u636e\u7c7b\u578b&#xff08;\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5217\u8868\u7b49&#xff09;\u3002<\/li>\n<\/ul>\n<h5 id=\"3.%20%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C\">3. \u57fa\u672c\u64cd\u4f5c<\/h5>\n<h6 id=\"%EF%BC%881%EF%BC%89%E8%AE%BF%E9%97%AE%E5%85%83%E7%B4%A0%EF%BC%88%E7%B4%A2%E5%BC%95%E4%B8%8E%E5%88%87%E7%89%87%EF%BC%89\">&#xff08;1&#xff09;\u8bbf\u95ee\u5143\u7d20&#xff08;\u7d22\u5f15\u4e0e\u5207\u7247&#xff09;<\/h6>\n<ul>\n<li>\u7d22\u5f15&#xff1a;\u901a\u8fc7\u00a0list[index]\u00a0\u8bbf\u95ee\u5355\u4e2a\u5143\u7d20&#xff08;\u652f\u6301\u6b63\u5411\u7d22\u5f15\u548c\u53cd\u5411\u7d22\u5f15&#xff09;\u3002\n<p>lst &#061; [&#034;a&#034;, &#034;b&#034;, &#034;c&#034;, &#034;d&#034;]<br \/>\nprint(lst[0])  # \u6b63\u5411\u7d22\u5f15&#xff1a;\u7b2c1\u4e2a\u5143\u7d20&#xff0c;\u8f93\u51fa &#034;a&#034;<br \/>\nprint(lst[-1])  # \u53cd\u5411\u7d22\u5f15&#xff1a;\u6700\u540e1\u4e2a\u5143\u7d20&#xff0c;\u8f93\u51fa &#034;d&#034;<\/p>\n<\/li>\n<li>\u5207\u7247&#xff1a;\u901a\u8fc7\u00a0list[start:end:step]\u00a0\u8bbf\u95ee\u5b50\u5217\u8868&#xff08;\u5de6\u95ed\u53f3\u5f00&#xff0c;step\u00a0\u4e3a\u6b65\u957f&#xff09;\u3002\n<p>lst &#061; [0, 1, 2, 3, 4, 5]<br \/>\nprint(lst[1:4])  # \u4ece\u7d22\u5f151\u52303&#xff0c;\u8f93\u51fa [1, 2, 3]<br \/>\nprint(lst[::2])  # \u6b65\u957f2&#xff0c;\u53d6\u6240\u6709\u5076\u6570\u7d22\u5f15\u5143\u7d20&#xff0c;\u8f93\u51fa [0, 2, 4]<br \/>\nprint(lst[::-1])  # \u6b65\u957f-1&#xff0c;\u53cd\u8f6c\u5217\u8868&#xff0c;\u8f93\u51fa [5, 4, 3, 2, 1, 0]<\/p>\n<\/li>\n<\/ul>\n<h6 id=\"%EF%BC%882%EF%BC%89%E4%BF%AE%E6%94%B9%E5%85%83%E7%B4%A0\">&#xff08;2&#xff09;\u4fee\u6539\u5143\u7d20<\/h6>\n<ul>\n<li>\u76f4\u63a5\u901a\u8fc7\u7d22\u5f15\u8d4b\u503c\u4fee\u6539\u5143\u7d20&#xff1a;\n<p>lst &#061; [1, 2, 3]<br \/>\nlst[1] &#061; 20  # \u4fee\u6539\u7d22\u5f151\u7684\u5143\u7d20&#xff0c;\u7ed3\u679c&#xff1a;[1, 20, 3]<\/p>\n<\/li>\n<\/ul>\n<h6 id=\"%EF%BC%883%EF%BC%89%E6%8B%BC%E6%8E%A5%E4%B8%8E%E9%87%8D%E5%A4%8D\">&#xff08;3&#xff09;\u62fc\u63a5\u4e0e\u91cd\u590d<\/h6>\n<ul>\n<li>\u62fc\u63a5&#xff1a;\u7528\u00a0&#043;\u00a0\u5408\u5e76\u4e24\u4e2a\u5217\u8868&#xff08;\u751f\u6210\u65b0\u5217\u8868&#xff0c;\u539f\u5217\u8868\u4e0d\u53d8&#xff09;\u3002\n<p>lst1 &#061; [1, 2]<br \/>\nlst2 &#061; [3, 4]<br \/>\nprint(lst1 &#043; lst2)  # \u8f93\u51fa [1, 2, 3, 4]<\/p>\n<\/li>\n<li>\u91cd\u590d&#xff1a;\u7528\u00a0*\u00a0\u91cd\u590d\u5217\u8868\u5143\u7d20&#xff08;\u751f\u6210\u65b0\u5217\u8868&#xff09;\u3002\n<p>lst &#061; [1, 2]<br \/>\nprint(lst * 3)  # \u8f93\u51fa [1, 2, 1, 2, 1, 2]<\/p>\n<\/li>\n<\/ul>\n<h6 id=\"%EF%BC%884%EF%BC%89%E6%88%90%E5%91%98%E5%88%A4%E6%96%AD\">&#xff08;4&#xff09;\u6210\u5458\u5224\u65ad<\/h6>\n<ul>\n<li>\u7528\u00a0in\u00a0\u5224\u65ad\u5143\u7d20\u662f\u5426\u5728\u5217\u8868\u4e2d&#xff0c;not in\u00a0\u5224\u65ad\u662f\u5426\u4e0d\u5728\u3002\n<p>lst &#061; [1, 2, 3]<br \/>\nprint(2 in lst)  # \u8f93\u51fa True<br \/>\nprint(4 not in lst)  # \u8f93\u51fa True<\/p>\n<\/li>\n<\/ul>\n<h6 id=\"%EF%BC%885%EF%BC%89%E9%95%BF%E5%BA%A6%E3%80%81%E6%9C%80%E5%A4%A7%20%2F%20%E6%9C%80%E5%B0%8F%E5%80%BC\">&#xff08;5&#xff09;\u957f\u5ea6\u3001\u6700\u5927 \/ \u6700\u5c0f\u503c<\/h6>\n<ul>\n<li>len(lst)&#xff1a;\u8fd4\u56de\u5217\u8868\u5143\u7d20\u4e2a\u6570\u3002<\/li>\n<li>max(lst)\/min(lst)&#xff1a;\u8fd4\u56de\u5217\u8868\u4e2d\u6700\u5927 \/ \u6700\u5c0f\u5143\u7d20&#xff08;\u5143\u7d20\u9700\u53ef\u6bd4\u8f83&#xff0c;\u5982\u5168\u4e3a\u6570\u5b57\u6216\u5168\u4e3a\u5b57\u7b26\u4e32&#xff09;\u3002\n<p>lst &#061; [3, 1, 4]<br \/>\nprint(len(lst))  # \u8f93\u51fa 3<br \/>\nprint(max(lst))  # \u8f93\u51fa 4<\/p>\n<\/li>\n<\/ul>\n<h5 id=\"4.%20%E5%B8%B8%E7%94%A8%E6%96%B9%E6%B3%95%EF%BC%88%E9%87%8D%E7%82%B9%EF%BC%89\">4. \u5e38\u7528\u65b9\u6cd5&#xff08;\u91cd\u70b9&#xff09;<\/h5>\n<table>\n<tr>\u65b9\u6cd5\u4f5c\u7528\u793a\u4f8b\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>append(x)<\/td>\n<td>\u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20\u00a0x&#xff08;\u4fee\u6539\u539f\u5217\u8868&#xff0c;\u65e0\u8fd4\u56de\u503c&#xff09;<\/td>\n<td>lst &#061; [1,2]; lst.append(3)<\/td>\n<td>[1, 2, 3]<\/td>\n<\/tr>\n<tr>\n<td>extend(iter)<\/td>\n<td>\u7528\u53ef\u8fed\u4ee3\u5bf9\u8c61\u00a0iterable&#xff08;\u5982\u5217\u8868\u3001\u5143\u7ec4&#xff09;\u4e2d\u7684\u5143\u7d20\u6269\u5c55\u5230\u5217\u8868&#xff08;\u6279\u91cf\u6dfb\u52a0&#xff0c;\u539f\u5217\u8868\u4e0d\u53d8&#xff09;<\/td>\n<td>lst &#061; [1,2]; lst.extend([3,4])<\/td>\n<td>[1, 2, 3, 4]<\/td>\n<\/tr>\n<tr>\n<td>insert(index, x)<\/td>\n<td>\u5728\u7d22\u5f15\u00a0index\u00a0\u5904\u63d2\u5165\u5143\u7d20\u00a0x&#xff08;\u539f\u5143\u7d20\u540e\u79fb&#xff09;<\/td>\n<td>lst &#061; [1,3]; lst.insert(1, 2)<\/td>\n<td>[1, 2, 3]<\/td>\n<\/tr>\n<tr>\n<td>remove(x)<\/td>\n<td>\u5220\u9664\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684\u5143\u7d20\u00a0x&#xff08;\u82e5\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;<\/td>\n<td>lst &#061; [1,2,2]; lst.remove(2)<\/td>\n<td>[1, 2]<\/td>\n<\/tr>\n<tr>\n<td>pop(index)<\/td>\n<td>\u5220\u9664\u5e76\u8fd4\u56de\u7d22\u5f15\u00a0index\u00a0\u5904\u7684\u5143\u7d20&#xff08;\u9ed8\u8ba4\u5220\u9664\u6700\u540e\u4e00\u4e2a&#xff0c;\u7d22\u5f15\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;<\/td>\n<td>lst &#061; [1,2,3]; lst.pop(1)<\/td>\n<td>\u8fd4\u56de\u00a02&#xff0c;\u5217\u8868\u53d8\u4e3a\u00a0[1, 3]<\/td>\n<\/tr>\n<tr>\n<td>clear()<\/td>\n<td>\u6e05\u7a7a\u5217\u8868&#xff08;\u4fdd\u7559\u7a7a\u5217\u8868&#xff09;<\/td>\n<td>lst &#061; [1,2]; lst.clear()<\/td>\n<td>[]<\/td>\n<\/tr>\n<tr>\n<td>index(x)<\/td>\n<td>\u8fd4\u56de\u5143\u7d20\u00a0x\u00a0\u5728\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684\u7d22\u5f15&#xff08;\u82e5\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;<\/td>\n<td>lst &#061; [1,2,3,2]; lst.index(2)<\/td>\n<td>\u8fd4\u56de\u00a01<\/td>\n<\/tr>\n<tr>\n<td>count(x)<\/td>\n<td>\u7edf\u8ba1\u5143\u7d20\u00a0x\u00a0\u5728\u5217\u8868\u4e2d\u51fa\u73b0\u7684\u6b21\u6570<\/td>\n<td>lst &#061; [1,2,2,3]; lst.count(2)<\/td>\n<td>\u8fd4\u56de\u00a02<\/td>\n<\/tr>\n<tr>\n<td>sort(key&#061;None, reverse&#061;False)<\/td>\n<td>\u5bf9\u5217\u8868\u5143\u7d20\u6392\u5e8f&#xff08;\u9ed8\u8ba4\u5347\u5e8f&#xff0c;reverse&#061;True\u00a0\u964d\u5e8f&#xff0c;\u4fee\u6539\u539f\u5217\u8868&#xff09;<\/td>\n<td>lst &#061; [3,1,2]; lst.sort()<\/td>\n<td>[1, 2, 3]<\/td>\n<\/tr>\n<tr>\n<td>reverse()<\/td>\n<td>\u53cd\u8f6c\u5217\u8868\u5143\u7d20\u987a\u5e8f&#xff08;\u4fee\u6539\u539f\u5217\u8868&#xff09;<\/td>\n<td>lst &#061; [1,2,3]; lst.reverse()<\/td>\n<td>[3, 2, 1]<\/td>\n<\/tr>\n<tr>\n<td>copy()<\/td>\n<td>\u590d\u5236\u5217\u8868&#xff08;\u6d45\u62f7\u8d1d&#xff0c;\u8fd4\u56de\u65b0\u5217\u8868&#xff09;<\/td>\n<td>lst &#061; [1,2]; new_lst &#061; lst.copy()<\/td>\n<td>new_lst\u00a0\u4e3a\u00a0[1,2]&#xff08;\u4e0e\u539f\u5217\u8868\u72ec\u7acb&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5 id=\"5.%20%E5%88%97%E8%A1%A8%E6%8E%A8%E5%AF%BC%E5%BC%8F%EF%BC%88%E9%AB%98%E6%95%88%E7%94%9F%E6%88%90%E5%88%97%E8%A1%A8%EF%BC%89\">5. \u5217\u8868\u63a8\u5bfc\u5f0f&#xff08;\u9ad8\u6548\u751f\u6210\u5217\u8868&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;[\u8868\u8fbe\u5f0f for \u53d8\u91cf in \u53ef\u8fed\u4ee3\u5bf9\u8c61 if \u6761\u4ef6]<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7528\u4e00\u884c\u4ee3\u7801\u751f\u6210\u5217\u8868&#xff0c;\u6bd4\u5faa\u73af\u66f4\u7b80\u6d01\u9ad8\u6548\u3002\n<p># \u751f\u62101-10\u7684\u5e73\u65b9\u5217\u8868<br \/>\nsquares &#061; [x**2 for x in range(1, 11)]<br \/>\nprint(squares)  # \u8f93\u51fa [1, 4, 9, &#8230;, 100]<\/p>\n<p># \u7b5b\u9009\u5076\u6570<br \/>\neven_numbers &#061; [x for x in range(1, 11) if x % 2 &#061;&#061; 0]<br \/>\nprint(even_numbers)  # \u8f93\u51fa [2, 4, 6, 8, 10]<\/p>\n<p># \u5d4c\u5957\u5217\u8868\u63a8\u5bfc\u5f0f&#xff08;\u4e8c\u7ef4\u5217\u8868\u8f6c\u4e00\u7ef4&#xff09;<br \/>\nmatrix &#061; [[1,2], [3,4], [5,6]]<br \/>\nflat &#061; [num for row in matrix for num in row]<br \/>\nprint(flat)  # \u8f93\u51fa [1, 2, 3, 4, 5, 6]<\/p>\n<p>#\u5d4c\u5957\u5faa\u73af&#xff08;\u7c7b\u4f3c\u53cc\u91cd for \u5faa\u73af&#xff09;&#xff1a;<br \/>\n[\u8868\u8fbe\u5f0f for \u53d8\u91cf1 in \u53ef\u8fed\u4ee3\u5bf9\u8c611 for \u53d8\u91cf2 in \u53ef\u8fed\u4ee3\u5bf9\u8c612]<br \/>\n\u6bd4\u5982 [i*j for i in [1,2] for j in [3,4]] \u2192 \u7ed3\u679c [3,4,6,8]\n<\/li>\n<\/ul>\n<h5 id=\"6.%20%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9\">6. \u6ce8\u610f\u4e8b\u9879<\/h5>\n<p>\u6ce8&#xff1a;\u62f7\u8d1d\u7684\u5dee\u5f02&#xff0c;\u672c\u8d28\u4e0a\u4f53\u73b0\u5728\u5bf9\u5d4c\u5957\u7684\u53ef\u53d8\u5bf9\u8c61\u7684\u5904\u7406\u4e0a\u3002\u56e0\u4e3a\u5bf9\u4e0d\u53ef\u53d8\u5bf9\u8c61\u6765\u8bf4&#xff0c;\u4e0d\u7ba1\u662f\u6df1\u62f7\u8d1d\u8fd8\u662f\u6d45\u62f7\u8d1d&#xff0c;\u5176\u5b9e\u90fd\u6ca1\u5565\u533a\u522b&#xff0c;\u56e0\u4e3a\u5b83\u4eec\u672c\u8eab\u4e0d\u80fd\u88ab\u4fee\u6539&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u590d\u5236\u4e86\u4e00\u4efd\u4e00\u6837\u7684 \u201c\u526f\u672c\u201d&#xff0c;\u800c\u4e14\u8fd9\u4e2a \u201c\u526f\u672c\u201d \u548c\u539f\u5bf9\u8c61\u7684\u503c\u3001\u5730\u5740\u5565\u7684\u90fd\u4e00\u6837\u3002<\/p>\n<h6 id=\"1.%20%E6%B5%85%E6%8B%B7%E8%B4%9D%EF%BC%88shallow%20copy%EF%BC%89\" style=\"background-color:transparent\">1. \u6d45\u62f7\u8d1d&#xff08;shallow copy&#xff09;<\/h6>\n<p>\u53ea\u62f7\u8d1d \u201c\u5916\u5c42\u5bf9\u8c61\u201d&#xff0c;\u4f46\u5bf9\u4e8e\u5916\u5c42\u5bf9\u8c61\u4e2d\u5d4c\u5957\u7684\u53ef\u53d8\u5b50\u5bf9\u8c61&#xff0c;\u4e0d\u91cd\u65b0\u521b\u5efa&#xff0c;\u800c\u662f\u76f4\u63a5\u5f15\u7528\u539f\u5bf9\u8c61\u7684\u5b50\u5bf9\u8c61&#xff08;\u5373\u5171\u4eab\u540c\u4e00\u4efd\u5b50\u5bf9\u8c61&#xff0c;\u540c\u4e00\u4e2a\u5730\u5740&#xff09;\u3002<\/p>\n<p>\u793a\u4f8b&#xff08;\u5173\u952e\u770b\u5d4c\u5957\u7684\u53ef\u53d8\u5bf9\u8c61&#xff09;&#xff1a;<\/p>\n<p>import copy<\/p>\n<p># \u539f\u5217\u8868&#xff1a;\u5916\u5c42\u662f\u5217\u8868&#xff08;\u53ef\u53d8&#xff09;&#xff0c;\u91cc\u9762\u5d4c\u5957\u4e86\u4e00\u4e2a\u5b50\u5217\u8868&#xff08;\u53ef\u53d8&#xff09;<br \/>\nold_list &#061; [1, 2, [3, 4]]  # 1\u30012\u662f\u4e0d\u53ef\u53d8\u5bf9\u8c61&#xff0c;[3,4]\u662f\u53ef\u53d8\u5b50\u5bf9\u8c61<\/p>\n<p># \u6d45\u62f7\u8d1d<br \/>\nnew_list &#061; old_list.copy()  # \u7b49\u4ef7\u4e8e old_list[:] \u6216 copy.copy(old_list)<\/p>\n<p># \u6d4b\u8bd51&#xff1a;\u4fee\u6539\u5916\u5c42\u7684\u4e0d\u53ef\u53d8\u5143\u7d20&#xff08;\u4e0d\u5f71\u54cd\u539f\u5217\u8868&#xff09;<br \/>\nnew_list[0] &#061; 100<br \/>\nprint(old_list)  # [1, 2, [3, 4]]&#xff08;\u539f\u5217\u8868\u4e0d\u53d8&#xff09;<br \/>\nprint(new_list)  # [100, 2, [3, 4]]<\/p>\n<p># \u6d4b\u8bd52&#xff1a;\u4fee\u6539\u5d4c\u5957\u7684\u53ef\u53d8\u5b50\u5bf9\u8c61&#xff08;\u539f\u5217\u8868\u548c\u65b0\u5217\u8868\u4f1a\u540c\u65f6\u53d8\u5316&#xff01;&#xff09;<br \/>\nnew_list[2][0] &#061; 300  # \u4fee\u6539\u5b50\u5217\u8868\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20<br \/>\nprint(old_list)  # [1, 2, [300, 4]]&#xff08;\u539f\u5217\u8868\u7684\u5b50\u5217\u8868\u88ab\u6539\u4e86&#xff01;&#xff09;<br \/>\nprint(new_list)  # [100, 2, [300, 4]]<\/p>\n<h6 id=\"2.%20%E6%B7%B1%E6%8B%B7%E8%B4%9D%EF%BC%88deep%20copy%EF%BC%89\">2. \u6df1\u62f7\u8d1d&#xff08;deep copy&#xff09;<\/h6>\n<p>\u4e0d\u4ec5\u62f7\u8d1d \u201c\u5916\u5c42\u5bf9\u8c61\u201d&#xff0c;\u8fd8\u4f1a\u9012\u5f52\u5730\u62f7\u8d1d\u6240\u6709\u5d4c\u5957\u7684\u53ef\u53d8\u5b50\u5bf9\u8c61&#xff0c;\u751f\u6210\u5b8c\u5168\u72ec\u7acb\u7684\u65b0\u5bf9\u8c61&#xff0c;\u4e0e\u539f\u5bf9\u8c61\u6ca1\u6709\u4efb\u4f55\u5171\u4eab\u5f15\u7528\u3002&#xff08;\u5168\u90e8\u7eaf\u7eaf\u65b0\u7684\u5730\u5740&#xff09;<\/p>\n<p>\u793a\u4f8b&#xff08;\u5d4c\u5957\u5bf9\u8c61\u5b8c\u5168\u72ec\u7acb&#xff09;&#xff1a;<\/p>\n<p>import copy<\/p>\n<p>old_list &#061; [1, 2, [3, 4]]  # \u540c\u4e0a<\/p>\n<p># \u6df1\u62f7\u8d1d<br \/>\nnew_list &#061; copy.deepcopy(old_list)<\/p>\n<p># \u6d4b\u8bd51&#xff1a;\u4fee\u6539\u5916\u5c42\u5143\u7d20&#xff08;\u4e0d\u5f71\u54cd\u539f\u5217\u8868&#xff0c;\u548c\u6d45\u62f7\u8d1d\u4e00\u6837&#xff09;<br \/>\nnew_list[0] &#061; 100<br \/>\nprint(old_list)  # [1, 2, [3, 4]]<br \/>\nprint(new_list)  # [100, 2, [3, 4]]<\/p>\n<p># \u6d4b\u8bd52&#xff1a;\u4fee\u6539\u5d4c\u5957\u7684\u53ef\u53d8\u5b50\u5bf9\u8c61&#xff08;\u539f\u5217\u8868\u5b8c\u5168\u4e0d\u53d7\u5f71\u54cd&#xff01;&#xff09;<br \/>\nnew_list[2][0] &#061; 300<br \/>\nprint(old_list)  # [1, 2, [3, 4]]&#xff08;\u539f\u5217\u8868\u7684\u5b50\u5217\u8868\u6ca1\u53d8&#xff01;&#xff09;<br \/>\nprint(new_list)  # [100, 2, [300, 4]]<\/p>\n<h6 id=\"%E6%80%BB%E7%BB%93%EF%BC%9A%E6%A0%B8%E5%BF%83%E5%8C%BA%E5%88%AB%E8%A1%A8\" style=\"background-color:transparent\">3.\u533a\u522b<\/h6>\n<table>\n<tr>\u573a\u666f\u6d45\u62f7\u8d1d&#xff08;shallow copy&#xff09;\u6df1\u62f7\u8d1d&#xff08;deep copy&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u5916\u5c42\u5bf9\u8c61<\/td>\n<td>\u590d\u5236\u65b0\u5bf9\u8c61&#xff0c;\u72ec\u7acb<\/td>\n<td>\u590d\u5236\u65b0\u5bf9\u8c61&#xff0c;\u72ec\u7acb<\/td>\n<\/tr>\n<tr>\n<td>\u5d4c\u5957\u7684\u53ef\u53d8\u5b50\u5bf9\u8c61<\/td>\n<td>\u4e0d\u590d\u5236&#xff0c;\u5171\u4eab\u5f15\u7528&#xff08;\u6539\u4e00\u4e2a\u5f71\u54cd\u53e6\u4e00\u4e2a&#xff09;<\/td>\n<td>\u9012\u5f52\u590d\u5236&#xff0c;\u751f\u6210\u65b0\u5b50\u5bf9\u8c61&#xff08;\u5b8c\u5168\u72ec\u7acb&#xff0c;\u4e92\u4e0d\u5f71\u54cd&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6027\u80fd<\/td>\n<td>\u66f4\u5feb&#xff08;\u590d\u5236\u5c11&#xff09;<\/td>\n<td>\u8f83\u6162&#xff08;\u9012\u5f52\u590d\u5236\u591a&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li>\n<p>Python \u4e2d\u7684\u5bf9\u8c61\u5206\u4e3a\u4e0d\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5143\u7ec4&#xff09;\u548c\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408&#xff09;\u3002<\/p>\n<\/li>\n<li>\u4e0d\u53ef\u53d8\u5bf9\u8c61&#xff1a;\u503c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u80fd\u4fee\u6539&#xff0c;\u4fee\u6539\u65f6\u4f1a\u751f\u6210\u65b0\u5bf9\u8c61&#xff08;\u672c\u8d28\u5c31\u662f\u751f\u6210\u65b0\u5730\u5740&#xff09;\u3002<\/li>\n<li>\u53ef\u53d8\u5bf9\u8c61&#xff1a;\u503c\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539&#xff0c;\u4fee\u6539\u65f6\u4e0d\u4f1a\u751f\u6210\u65b0\u5bf9\u8c61&#xff08;\u5982\u00a0list1[0]&#061;10\u00a0\u662f\u5728\u539f\u5730\u5740\u4e0a\u6539&#xff09;\u3002<\/li>\n<li>\u5217\u8868\u5207\u7247&#xff1a;new_list &#061; old_list[:]<\/li>\n<li>list.copy()\u00a0\u65b9\u6cd5&#xff1a;new_list &#061; old_list.copy()<\/li>\n<li>copy\u00a0\u6a21\u5757\u7684\u00a0copy()\u00a0\u51fd\u6570&#xff1a;new_list &#061; copy.copy(old_list)&#xff08;\u63a8\u8350&#xff09;<\/li>\n<li>copy\u6a21\u5757\u91cc\u7684copy\u51fd\u6570\u633a\u4e07\u80fd\u7684&#xff0c;\u4e0d\u7ba1\u662f\u5217\u8868\u3001\u5b57\u5178\u8fd8\u662f\u96c6\u5408&#xff0c;\u90fd\u80fd\u7528\u5b83\u6765\u505a\u6d45\u62f7\u8d1d\u3002\u8fd9\u6837\u5c31\u4e0d\u7528\u8bb0\u6bcf\u4e2a\u7c7b\u578b\u5404\u81ea\u7684\u62f7\u8d1d\u65b9\u6cd5&#xff0c;\u4e00\u4e2a\u51fd\u6570\u641e\u5b9a\u597d\u591a\u7c7b\u578b\u3002<\/li>\n<li>copy\u00a0\u6a21\u5757\u7684\u00a0deepcopy()\u00a0\u51fd\u6570&#xff1a;new_list &#061; copy.deepcopy(old_list)<\/li>\n<\/ul>\n<h6 id=\"3.%E5%BA%94%E7%94%A8\" style=\"background-color:transparent\">4.\u5e94\u7528<\/h6>\n<p>\u6d45\u62f7\u8d1d&#xff1a;\u5b83\u901f\u5ea6\u5feb&#xff0c;\u5360\u7528\u5185\u5b58\u5c11\u3002\u5982\u679c\u4f60\u7684\u5bf9\u8c61\u91cc\u6ca1\u6709\u5d4c\u5957\u53ef\u53d8\u5bf9\u8c61&#xff0c;\u6216\u8005\u4f60\u4e0d\u9700\u8981\u5bf9\u5d4c\u5957\u53ef\u53d8\u5bf9\u8c61\u8fdb\u884c\u72ec\u7acb\u4fee\u6539&#xff0c;\u5c31\u53ef\u4ee5\u7528\u6d45\u62f7\u8d1d\u3002\u6bd4\u5982\u4f60\u53ea\u662f\u60f3\u590d\u5236\u4e00\u4e2a\u7b80\u5355\u7684\u5217\u8868&#xff0c;\u91cc\u9762\u90fd\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff08;\u50cf\u6574\u6570\u3001\u5b57\u7b26\u4e32&#xff09;&#xff0c;\u6d45\u62f7\u8d1d\u5c31\u591f&#xff0c;\u53c8\u5feb\u53c8\u7701\u8d44\u6e90\u3002<\/p>\n<p>\u6df1\u62f7\u8d1d&#xff1a;\u5f53\u4f60\u9700\u8981\u5b8c\u5168\u72ec\u7acb\u7684\u526f\u672c&#xff0c;\u5c24\u5176\u662f\u5bf9\u8c61\u6709\u5d4c\u5957\u53ef\u53d8\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u4f60\u8981\u4fee\u6539\u526f\u672c\u91cc\u7684\u5d4c\u5957\u5bf9\u8c61&#xff0c;\u53c8\u4e0d\u60f3\u5f71\u54cd\u539f\u5bf9\u8c61\u7684\u65f6\u5019&#xff0c;\u6df1\u62f7\u8d1d\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n<p>\u4e00\u53e5\u8bdd\u8bb0\u4f4f&#xff1a;<\/p>\n<ul>\n<li>\u6d45\u62f7\u8d1d&#xff1a;\u201c\u8868\u9762\u590d\u5236\u201d&#xff0c;\u5d4c\u5957\u7684\u53ef\u53d8\u5bf9\u8c61\u8fd8\u662f \u201c\u4e00\u5bb6\u4eba\u201d\u3002<\/li>\n<li>\u6df1\u62f7\u8d1d&#xff1a;\u201c\u8fde\u6839\u590d\u5236\u201d&#xff0c;\u5d4c\u5957\u7684\u53ef\u53d8\u5bf9\u8c61\u4e5f\u53d8\u6210 \u201c\u4e24\u5bb6\u4eba\u201d&#xff0c;\u5f7b\u5e95\u72ec\u7acb\u3002<\/li>\n<li>\n<p>import copy<br \/>\nlst &#061; [1, [2, 3]]<br \/>\nshallow &#061; lst.copy()<br \/>\ndeep &#061; copy.deepcopy(lst)<br \/>\nlst[1].append(4)  # \u4fee\u6539\u5b50\u5217\u8868<br \/>\nprint(shallow)  # \u8f93\u51fa [1, [2, 3, 4]]&#xff08;\u6d45\u62f7\u8d1d\u53d7\u5f71\u54cd&#xff09;<br \/>\nprint(deep)    # \u8f93\u51fa [1, [2, 3]]&#xff08;\u6df1\u62f7\u8d1d\u4e0d\u53d7\u5f71\u54cd&#xff09;<\/p>\n<\/li>\n<li>\u5217\u8868\u662f\u53ef\u53d8\u5bf9\u8c61&#xff1a;\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u65f6&#xff0c;\u4fee\u6539\u5217\u8868\u4f1a\u5f71\u54cd\u5916\u90e8\u539f\u5217\u8868&#xff08;\u4f20\u5f15\u7528&#xff09;&#xff0c;\u56e0\u4e3a\u4f20\u5165\u65f6\u5171\u7528\u4e00\u4e2a\u5730\u5740&#xff0c;\u8fd9\u548c\u6d45\u62f7\u8d1d\u4e0e\u6df1\u62f7\u8d1d\u4e0d\u540c&#xff0c;\u8bf7\u8bfb\u8005\u533a\u5206\u5f00\u3002<\/li>\n<\/ul>\n<h4>\u4e8c\u3001\u5b57\u5178&#xff08;Dictionary&#xff09;<\/h4>\n<h5>1. \u5b9a\u4e49\u4e0e\u8868\u793a<\/h5>\n<ul>\n<li>\u5b57\u5178\u662f Python \u4e2d\u952e\u503c\u5bf9\u6620\u5c04\u7684\u53ef\u53d8\u6570\u636e\u7c7b\u578b&#xff0c;\u7528\u4e8e\u5b58\u50a8\u5173\u8054\u578b\u6570\u636e\u3002<\/li>\n<li>\u8868\u793a\u65b9\u5f0f&#xff1a;\u7528\u00a0{}\u00a0\u5305\u88f9&#xff0c;\u5143\u7d20\u4e3a\u00a0\u952e: \u503c\u00a0\u5bf9&#xff0c;\u952e\u4e0e\u503c\u4e4b\u95f4\u7528\u5192\u53f7\u5206\u9694&#xff0c;\u952e\u503c\u5bf9\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\u3002\n<p>dict1 &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 18, &#034;hobby&#034;: [&#034;\u7bee\u7403&#034;, &#034;\u6e38\u620f&#034;]}  # \u666e\u901a\u5b57\u5178<br \/>\nempty_dict &#061; {}  # \u7a7a\u5b57\u5178<br \/>\ndict_from_list &#061; dict([(&#034;a&#034;, 1), (&#034;b&#034;, 2)])  # \u7528dict()\u51fd\u6570\u4ece\u5217\u8868\u751f\u6210<\/p>\n<\/li>\n<\/ul>\n<h5>2. \u6838\u5fc3\u7279\u6027<\/h5>\n<ul>\n<li>\u952e\u503c\u5bf9\u6620\u5c04&#xff1a;\u901a\u8fc7\u552f\u4e00\u7684 \u201c\u952e\u201d \u8bbf\u95ee\u5bf9\u5e94\u7684 \u201c\u503c\u201d&#xff0c;\u952e\u662f\u8bbf\u95ee\u7684\u552f\u4e00\u6807\u8bc6\u3002<\/li>\n<li>\u952e\u7684\u7ea6\u675f&#xff1a;\u952e\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff08;\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5143\u7ec4\u7b49&#xff09;&#xff0c;\u4e14\u540c\u4e00\u5b57\u5178\u4e2d\u952e\u4e0d\u53ef\u91cd\u590d&#xff08;\u91cd\u590d\u4f1a\u88ab\u8986\u76d6&#xff09;\u3002<\/li>\n<li>\u503c\u7684\u7075\u6d3b\u6027&#xff1a;\u503c\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u636e\u7c7b\u578b&#xff08;\u5305\u62ec\u5217\u8868\u3001\u5b57\u5178\u3001\u51fd\u6570\u7b49&#xff09;&#xff0c;\u65e0\u9650\u5236\u3002<\/li>\n<li>\u53ef\u53d8\u6027&#xff1a;\u652f\u6301\u52a8\u6001\u6dfb\u52a0\u3001\u4fee\u6539\u3001\u5220\u9664\u952e\u503c\u5bf9&#xff08;\u5185\u5b58\u5730\u5740\u4e0d\u53d8&#xff0c;\u5185\u5bb9\u53ef\u53d8&#xff09;\u3002<\/li>\n<li>\u6709\u5e8f\u6027&#xff1a;Python 3.7&#043; \u540e\u5b57\u5178\u662f\u6709\u5e8f\u7684&#xff08;\u6309\u63d2\u5165\u987a\u5e8f\u4fdd\u5b58&#xff09;&#xff0c;\u4e4b\u524d\u7248\u672c\u65e0\u5e8f\u3002<\/li>\n<\/ul>\n<h5>3. \u57fa\u672c\u64cd\u4f5c<\/h5>\n<h6>&#xff08;1&#xff09;\u8bbf\u95ee\u503c<\/h6>\n<ul>\n<li>\u901a\u8fc7\u952e\u76f4\u63a5\u8bbf\u95ee&#xff1a;dict[key]&#xff08;\u952e\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;\u3002\n<p>info &#061; {&#034;city&#034;: &#034;\u5317\u4eac&#034;, &#034;area&#034;: 16410}<br \/>\nprint(info[&#034;city&#034;])  # \u8f93\u51fa &#034;\u5317\u4eac&#034;<\/p>\n<\/li>\n<li>\u901a\u8fc7\u00a0get()\u00a0\u65b9\u6cd5\u8bbf\u95ee&#xff1a;dict.get(key, default)&#xff08;\u952e\u4e0d\u5b58\u5728\u5219\u8fd4\u56de\u9ed8\u8ba4\u503c&#xff0c;\u907f\u514d\u62a5\u9519&#xff09;\u3002\n<p>print(info.get(&#034;population&#034;, &#034;\u672a\u77e5&#034;))  # \u8f93\u51fa &#034;\u672a\u77e5&#034;&#xff08;\u952e&#034;population&#034;\u4e0d\u5b58\u5728&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;2&#xff09;\u4fee\u6539 \/ \u65b0\u589e\u952e\u503c\u5bf9<\/h6>\n<ul>\n<li>\u76f4\u63a5\u8d4b\u503c&#xff1a;\u952e\u5b58\u5728\u5219\u4fee\u6539\u503c&#xff0c;\u952e\u4e0d\u5b58\u5728\u5219\u65b0\u589e\u952e\u503c\u5bf9\u3002\n<p>info[&#034;area&#034;] &#061; 16411  # \u4fee\u6539\u5df2\u6709\u952e\u7684\u503c<br \/>\ninfo[&#034;population&#034;] &#061; 2184  # \u65b0\u589e\u952e\u503c\u5bf9<br \/>\nprint(info)  # \u8f93\u51fa {&#034;city&#034;: &#034;\u5317\u4eac&#034;, &#034;area&#034;: 16411, &#034;population&#034;: 2184}<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;3&#xff09;\u5220\u9664\u952e\u503c\u5bf9<\/h6>\n<ul>\n<li>del dict[key]&#xff1a;\u5220\u9664\u6307\u5b9a\u952e\u503c\u5bf9&#xff08;\u952e\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;\u3002<\/li>\n<li>dict.pop(key, default)&#xff1a;\u5220\u9664\u5e76\u8fd4\u56de\u6307\u5b9a\u952e\u7684\u503c&#xff08;\u952e\u4e0d\u5b58\u5728\u5219\u8fd4\u56de\u9ed8\u8ba4\u503c&#xff09;\u3002<\/li>\n<li>dict.clear()&#xff1a;\u6e05\u7a7a\u5b57\u5178\u6240\u6709\u952e\u503c\u5bf9&#xff08;\u4fdd\u7559\u7a7a\u5b57\u5178&#xff09;\u3002\n<p>del info[&#034;area&#034;]  # \u5220\u9664&#034;area&#034;\u952e\u503c\u5bf9<br \/>\nprint(info.pop(&#034;city&#034;, &#034;\u65e0&#034;))  # \u8f93\u51fa &#034;\u5317\u4eac&#034;&#xff08;\u5220\u9664\u5e76\u8fd4\u56de\u503c&#xff09;<br \/>\ninfo.clear()  # \u6e05\u7a7a\u5b57\u5178&#xff0c;\u7ed3\u679c&#xff1a;{}<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;4&#xff09;\u5176\u4ed6\u57fa\u7840\u64cd\u4f5c<\/h6>\n<ul>\n<li>\u62fc\u63a5 \/ \u5408\u5e76&#xff1a;\u7528\u00a0dict.update(other_dict)\u00a0\u5408\u5e76\u53e6\u4e00\u4e2a\u5b57\u5178&#xff08;\u8986\u76d6\u91cd\u590d\u952e&#xff0c;\u540e\u6765\u8005\u5c45\u4e0a&#xff09;\u3002\n<p>a &#061; {&#034;x&#034;: 1, &#034;y&#034;: 2}<br \/>\nb &#061; {&#034;y&#034;: 3, &#034;z&#034;: 4}<br \/>\na.update(b)  # a\u53d8\u4e3a {&#034;x&#034;: 1, &#034;y&#034;: 3, &#034;z&#034;: 4}&#xff08;&#034;y&#034;\u88ab\u8986\u76d6&#xff09;<\/p>\n<\/li>\n<li>\u6210\u5458\u5224\u65ad&#xff1a;\u7528\u00a0in\u00a0\/\u00a0not in\u00a0\u5224\u65ad\u952e\u662f\u5426\u5b58\u5728&#xff08;\u4ec5\u5224\u65ad\u952e&#xff0c;\u4e0d\u5224\u65ad\u503c&#xff09;\u3002\n<p>print(&#034;x&#034; in a)  # \u8f93\u51fa True&#xff08;\u5224\u65ad\u952e&#034;x&#034;\u662f\u5426\u5b58\u5728&#xff09;<\/p>\n<\/li>\n<li>\u957f\u5ea6&#xff1a;len(dict)\u00a0\u8fd4\u56de\u952e\u503c\u5bf9\u7684\u6570\u91cf\u3002\n<p>print(len(a))  # \u8f93\u51fa 3<\/p>\n<\/li>\n<\/ul>\n<h5>4. \u5e38\u7528\u65b9\u6cd5&#xff08;\u91cd\u70b9&#xff09;<\/h5>\n<table>\n<tr>\u65b9\u6cd5\u4f5c\u7528\u793a\u4f8b\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>dict.keys()<\/td>\n<td>\u8fd4\u56de\u6240\u6709\u952e\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;\u53ef\u8f6c\u6210\u5217\u8868&#xff09;<\/td>\n<td>info &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 18}<br \/>\ninfo.keys()<br \/>\nlist(info.keys())<\/td>\n<td>dict_keys([&#039;name&#039;, &#039;age&#039;])<br \/>\n[&#039;name&#039;, &#039;age&#039;]<\/td>\n<\/tr>\n<tr>\n<td>dict.values()<\/td>\n<td>\u8fd4\u56de\u6240\u6709\u503c\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;\u53ef\u8f6c\u6210\u5217\u8868&#xff09;<\/td>\n<td>info &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 18}<br \/>\ninfo.values()<br \/>\nlist(info.values())<\/td>\n<td>dict_values([&#039;\u5f20\u4e09&#039;, 18])<br \/>\n[&#039;\u5f20\u4e09&#039;, 18]<\/td>\n<\/tr>\n<tr>\n<td>dict.items()<\/td>\n<td>\u8fd4\u56de\u6240\u6709\u952e\u503c\u5bf9\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;\u6bcf\u4e2a\u5143\u7d20\u4e3a\u00a0(\u952e, \u503c)\u00a0\u5143\u7ec4&#xff09;<\/td>\n<td>info &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 18}<br \/>\ninfo.items()<br \/>\nlist(info.items())<\/td>\n<td>dict_items([(&#039;name&#039;, &#039;\u5f20\u4e09&#039;), (&#039;age&#039;, 18)])<br \/>\n[(&#039;name&#039;, &#039;\u5f20\u4e09&#039;), (&#039;age&#039;, 18)]<\/td>\n<\/tr>\n<tr>\n<td>dict.copy()<\/td>\n<td>\u590d\u5236\u5b57\u5178&#xff08;\u6d45\u62f7\u8d1d&#xff0c;\u751f\u6210\u65b0\u5b57\u5178&#xff09;<\/td>\n<td>info &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;, &#034;age&#034;: 18}<br \/>\ninfo_copy &#061; info.copy()<br \/>\ninfo_copy<\/td>\n<td>{&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 18}<\/td>\n<\/tr>\n<tr>\n<td>dict.setdefault(key, default)<\/td>\n<td>\u82e5\u952e\u4e0d\u5b58\u5728\u5219\u65b0\u589e&#xff08;\u503c\u4e3a\u00a0default&#xff09;&#xff0c;\u5b58\u5728\u5219\u8fd4\u56de\u5bf9\u5e94\u503c&#xff08;\u4e0d\u4fee\u6539\u539f\u5b57\u5178&#xff09;<\/td>\n<td>info &#061; {&#034;name&#034;: &#034;\u5f20\u4e09&#034;}<br \/>\ninfo.setdefault(&#034;age&#034;, 18)<br \/>\ninfo<br \/>\ninfo.setdefault(&#034;name&#034;, &#034;\u674e\u56db&#034;)<br \/>\ninfo<\/td>\n<td>18<br \/>\n{&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 18}<br \/>\n\u5f20\u4e09<br \/>\n{&#039;name&#039;: &#039;\u5f20\u4e09&#039;, &#039;age&#039;: 18}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5 style=\"background-color:transparent\">5. \u5b57\u5178\u63a8\u5bfc\u5f0f&#xff08;\u9ad8\u6548\u751f\u6210\u5b57\u5178&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;{\u952e\u8868\u8fbe\u5f0f: \u503c\u8868\u8fbe\u5f0f for \u53d8\u91cf in \u53ef\u8fed\u4ee3\u5bf9\u8c61 if \u6761\u4ef6}<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7528\u4e00\u884c\u4ee3\u7801\u751f\u6210\u5b57\u5178&#xff0c;\u6bd4\u5faa\u73af\u66f4\u7b80\u6d01\u3002\n<p># \u751f\u62101-5\u7684\u5e73\u65b9\u5b57\u5178<br \/>\nsquares &#061; {x: x**2 for x in range(1, 6)}<br \/>\nprint(squares)  # \u8f93\u51fa {1:1, 2:4, 3:9, 4:16, 5:25}<\/p>\n<p># \u7b5b\u9009\u503c\u4e3a\u5076\u6570\u7684\u952e\u503c\u5bf9<br \/>\neven_squares &#061; {k: v for k, v in squares.items() if v % 2 &#061;&#061; 0}<br \/>\nprint(even_squares)  # \u8f93\u51fa {2:4, 4:16}<\/p>\n<\/li>\n<\/ul>\n<h5>6. \u6ce8\u610f\u4e8b\u9879<\/h5>\n<ul>\n<li>\u6d45\u62f7\u8d1d\u7279\u6027&#xff1a;dict.copy()\u00a0\u6216\u00a0dict\u00a0\u51fd\u6570\u590d\u5236\u7684\u662f\u6d45\u62f7\u8d1d&#xff0c;\u82e5\u5b57\u5178\u4e2d\u5d4c\u5957\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u5217\u8868&#xff09;&#xff0c;\u4fee\u6539\u5d4c\u5957\u5bf9\u8c61\u4f1a\u5f71\u54cd\u539f\u5b57\u5178\u548c\u62f7\u8d1d\u5b57\u5178\u3002<\/li>\n<li>\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570&#xff1a;\u5b57\u5178\u662f\u53ef\u53d8\u5bf9\u8c61&#xff0c;\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u51fd\u6570\u65f6&#xff0c;\u4fee\u6539\u5b57\u5178\u4f1a\u5f71\u54cd\u5916\u90e8\u539f\u5b57\u5178&#xff08;\u540c\u5217\u8868\u7684\u4f20\u5f15\u7528\u7279\u6027&#xff09;\u3002<\/li>\n<\/ul>\n<h4 style=\"background-color:transparent\">\u4e09\u3001\u5143\u7ec4&#xff08;Tuple&#xff09;<\/h4>\n<h5>1. \u5b9a\u4e49\u4e0e\u8868\u793a<\/h5>\n<ul>\n<li>\u5143\u7ec4\u662f Python \u4e2d\u4e0d\u53ef\u53d8\u7684\u6709\u5e8f\u5e8f\u5217&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4e0d\u53ef\u4fee\u6539\u7684\u4e00\u7ec4\u6570\u636e\u3002<\/li>\n<li>\u8868\u793a\u65b9\u5f0f&#xff1a;\u7528\u00a0()\u00a0\u5305\u88f9\u5143\u7d20&#xff0c;\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\u3002\u4f8b\u5982&#xff1a;\n<p>tuple1 &#061; (10, &#034;\u82f9\u679c&#034;, 3.14)  # \u666e\u901a\u5143\u7ec4<br \/>\nsingle_tuple &#061; (5,)  # \u5355\u5143\u7d20\u5143\u7ec4&#xff08;\u5fc5\u987b\u52a0\u9017\u53f7&#xff0c;\u5426\u5219\u89c6\u4e3a\u666e\u901a\u62ec\u53f7&#xff09;<br \/>\nempty_tuple &#061; ()  # \u7a7a\u5143\u7ec4<br \/>\ntuple_from_list &#061; tuple([1, 2, 3])  # \u7528tuple()\u51fd\u6570\u4ece\u5217\u8868\u751f\u6210<\/p>\n<\/li>\n<\/ul>\n<h5>2. \u6838\u5fc3\u7279\u6027<\/h5>\n<ul>\n<li>\u4e0d\u53ef\u53d8\u6027&#xff1a;\u5143\u7ec4\u521b\u5efa\u540e&#xff0c;\u5143\u7d20\u7684\u6570\u91cf\u3001\u987a\u5e8f\u3001\u503c\u4e0d\u53ef\u4fee\u6539&#xff08;\u4e0d\u80fd\u65b0\u589e\u3001\u5220\u9664\u3001\u66ff\u6362\u5143\u7d20&#xff09;\u3002\n<ul>\n<li>\u4f8b\u5916&#xff1a;\u82e5\u5143\u7d20\u662f\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u5217\u8868&#xff09;&#xff0c;\u53ef\u4fee\u6539\u53ef\u53d8\u5bf9\u8c61\u7684\u5185\u90e8\u5185\u5bb9&#xff08;\u4f46\u5143\u7ec4\u672c\u8eab\u7684\u7ed3\u6784\u4e0d\u53d8&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6709\u5e8f\u6027&#xff1a;\u5143\u7d20\u6709\u56fa\u5b9a\u987a\u5e8f&#xff0c;\u53ef\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee&#xff08;\u540c\u5217\u8868&#xff09;\u3002<\/li>\n<li>\u53ef\u91cd\u590d\u6027&#xff1a;\u5141\u8bb8\u5305\u542b\u91cd\u590d\u5143\u7d20\u3002<\/li>\n<li>\u5143\u7d20\u7075\u6d3b\u6027&#xff1a;\u53ef\u5b58\u50a8\u4efb\u610f\u6570\u636e\u7c7b\u578b&#xff08;\u5305\u62ec\u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u7b49&#xff09;\u3002<\/li>\n<\/ul>\n<h5>3. \u57fa\u672c\u64cd\u4f5c<\/h5>\n<h6>&#xff08;1&#xff09;\u8bbf\u95ee\u5143\u7d20&#xff08;\u7d22\u5f15\u4e0e\u5207\u7247&#xff09;<\/h6>\n<ul>\n<li>\u7d22\u5f15&#xff1a;tuple[index]&#xff08;\u6b63\u5411\u7d22\u5f15\u4ece 0 \u5f00\u59cb&#xff0c;\u53cd\u5411\u7d22\u5f15\u4ece &#8211; 1 \u5f00\u59cb&#xff09;\u3002\n<p>t &#061; (&#034;a&#034;, &#034;b&#034;, &#034;c&#034;, &#034;d&#034;)<br \/>\nprint(t[1])  # \u8f93\u51fa &#034;b&#034;&#xff08;\u6b63\u5411\u7d22\u5f15&#xff09;<br \/>\nprint(t[-2])  # \u8f93\u51fa &#034;c&#034;&#xff08;\u53cd\u5411\u7d22\u5f15&#xff09;<\/p>\n<\/li>\n<li>\u5207\u7247&#xff1a;tuple[start:end:step]&#xff08;\u5de6\u95ed\u53f3\u5f00&#xff0c;\u8fd4\u56de\u65b0\u5143\u7ec4&#xff09;\u3002\n<p>print(t[1:3])  # \u8f93\u51fa (&#034;b&#034;, &#034;c&#034;)<br \/>\nprint(t[::-1])  # \u8f93\u51fa (&#034;d&#034;, &#034;c&#034;, &#034;b&#034;, &#034;a&#034;)&#xff08;\u53cd\u8f6c&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;2&#xff09;\u62fc\u63a5\u4e0e\u91cd\u590d<\/h6>\n<ul>\n<li>\u62fc\u63a5&#xff1a;tuple1 &#043; tuple2&#xff08;\u751f\u6210\u65b0\u5143\u7ec4&#xff0c;\u539f\u5143\u7ec4\u4e0d\u53d8&#xff09;\u3002\n<p>t1 &#061; (1, 2)<br \/>\nt2 &#061; (3, 4)<br \/>\nprint(t1 &#043; t2)  # \u8f93\u51fa (1, 2, 3, 4)<\/p>\n<\/li>\n<li>\u91cd\u590d&#xff1a;tuple * n&#xff08;\u751f\u6210\u65b0\u5143\u7ec4&#xff0c;\u5143\u7d20\u91cd\u590d n \u6b21&#xff09;\u3002\n<p>print(t1 * 3)  # \u8f93\u51fa (1, 2, 1, 2, 1, 2)<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;3&#xff09;\u6210\u5458\u5224\u65ad<\/h6>\n<ul>\n<li>\u7528\u00a0in\u00a0\/\u00a0not in\u00a0\u5224\u65ad\u5143\u7d20\u662f\u5426\u5728\u5143\u7ec4\u4e2d\u3002\n<p>print(&#034;b&#034; in t)  # \u8f93\u51fa True<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;4&#xff09;\u957f\u5ea6\u3001\u6700\u5927 \/ \u6700\u5c0f\u503c<\/h6>\n<ul>\n<li>len(tuple)&#xff1a;\u8fd4\u56de\u5143\u7d20\u4e2a\u6570\u3002<\/li>\n<li>max(tuple)\u00a0\/\u00a0min(tuple)&#xff1a;\u8fd4\u56de\u6700\u5927 \/ \u6700\u5c0f\u5143\u7d20&#xff08;\u5143\u7d20\u9700\u53ef\u6bd4\u8f83&#xff09;\u3002\n<p>nums &#061; (3, 1, 4)<br \/>\nprint(len(nums))  # \u8f93\u51fa 3<br \/>\nprint(max(nums))  # \u8f93\u51fa 4<\/p>\n<\/li>\n<\/ul>\n<h5>4. \u5e38\u7528\u65b9\u6cd5<\/h5>\n<table>\n<tr>\u65b9\u6cd5\u4f5c\u7528\u793a\u4f8b\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>tuple.count(value)<\/td>\n<td style=\"width:336px\">\u7edf\u8ba1\u5143\u7d20\u00a0value\u00a0\u5728\u5143\u7ec4\u4e2d\u51fa\u73b0\u7684\u6b21\u6570<\/td>\n<td style=\"width:160px\">(1, 2, 2, 3).count(2)<\/td>\n<td style=\"width:67px\">2<\/td>\n<\/tr>\n<tr>\n<td>tuple.index(value)<\/td>\n<td style=\"width:336px\">\u8fd4\u56de\u5143\u7d20\u00a0value\u00a0\u5728\u5143\u7ec4\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15&#xff08;\u5143\u7d20\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;<\/td>\n<td style=\"width:160px\">(&#034;a&#034;, &#034;b&#034;, &#034;a&#034;).index(&#034;a&#034;)<\/td>\n<td style=\"width:67px\">0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>5. \u6ce8\u610f\u4e8b\u9879<\/h5>\n<ul>\n<li>\u4e0d\u53ef\u53d8\u6027\u7684\u7ec6\u8282&#xff1a;\u5143\u7ec4\u672c\u8eab\u4e0d\u53ef\u4fee\u6539&#xff0c;\u4f46\u5982\u679c\u5143\u7d20\u662f\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u5217\u8868&#xff09;&#xff0c;\u53ef\u4fee\u6539\u8be5\u5143\u7d20\u7684\u5185\u90e8\u5185\u5bb9\u3002\n<p>t &#061; (1, [2, 3])<br \/>\nt[1].append(4)  # \u4fee\u6539\u5143\u7ec4\u4e2d\u7684\u5217\u8868\u5143\u7d20&#xff08;\u5141\u8bb8&#xff09;<br \/>\nprint(t)  # \u8f93\u51fa (1, [2, 3, 4])<\/p>\n<\/li>\n<li>\u4e0e\u5217\u8868\u7684\u533a\u522b&#xff1a;\u5143\u7ec4\u4e0d\u53ef\u53d8&#xff0c;\u9002\u5408\u5b58\u50a8\u56fa\u5b9a\u6570\u636e&#xff08;\u5982\u914d\u7f6e\u9879\u3001\u5750\u6807&#xff09;&#xff1b;\u5217\u8868\u53ef\u53d8&#xff0c;\u9002\u5408\u5b58\u50a8\u52a8\u6001\u6570\u636e\u3002<\/li>\n<li>\u4f5c\u4e3a\u5b57\u5178\u7684\u952e&#xff1a;\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff0c;\u53ef\u4f5c\u4e3a\u5b57\u5178\u7684\u952e&#xff1b;\u5217\u8868\u4e0d\u53ef\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\u3002<\/li>\n<\/ul>\n<h4 style=\"background-color:transparent\">\u56db\u3001\u96c6\u5408&#xff08;Set&#xff09;<\/h4>\n<h5>1. \u5b9a\u4e49\u4e0e\u8868\u793a<\/h5>\n<ul>\n<li>\u96c6\u5408\u662f Python \u4e2d\u65e0\u5e8f\u3001\u552f\u4e00\u7684\u53ef\u53d8\u6570\u636e\u96c6\u5408&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4e0d\u91cd\u590d\u7684\u5143\u7d20\u3002<\/li>\n<li>\u8868\u793a\u65b9\u5f0f&#xff1a;\u7528\u00a0{}\u00a0\u5305\u88f9\u5143\u7d20&#xff08;\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694&#xff09;&#xff0c;\u6216\u7528\u00a0set()\u00a0\u51fd\u6570\u751f\u6210\u3002\u4f8b\u5982&#xff1a;\n<p>set1 &#061; {1, 2, 3, 4}  # \u666e\u901a\u96c6\u5408&#xff08;\u81ea\u52a8\u53bb\u91cd&#xff09;<br \/>\nempty_set &#061; set()  # \u7a7a\u96c6\u5408&#xff08;\u4e0d\u80fd\u7528{}&#xff0c;{}\u8868\u793a\u7a7a\u5b57\u5178&#xff09;<br \/>\nset_from_list &#061; set([1, 2, 2, 3])  # \u4ece\u5217\u8868\u751f\u6210\u96c6\u5408&#xff08;\u81ea\u52a8\u53bb\u91cd&#xff09;\u2192 {1, 2, 3}<\/p>\n<\/li>\n<\/ul>\n<h5>2. \u6838\u5fc3\u7279\u6027<\/h5>\n<ul>\n<li>\u552f\u4e00\u6027&#xff1a;\u96c6\u5408\u4e2d\u5143\u7d20\u4e0d\u53ef\u91cd\u590d&#xff0c;\u81ea\u52a8\u53bb\u91cd&#xff08;\u6dfb\u52a0\u91cd\u590d\u5143\u7d20\u4f1a\u88ab\u5ffd\u7565&#xff09;\u3002<\/li>\n<li>\u65e0\u5e8f\u6027&#xff1a;\u5143\u7d20\u6ca1\u6709\u56fa\u5b9a\u987a\u5e8f&#xff0c;\u4e0d\u80fd\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee&#xff08;\u4e0e\u5217\u8868\u3001\u5143\u7ec4\u7684\u6838\u5fc3\u533a\u522b&#xff09;\u3002<\/li>\n<li>\u5143\u7d20\u7ea6\u675f&#xff1a;\u5143\u7d20\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff08;\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u5143\u7ec4\u7b49&#xff09;&#xff0c;\u4e0d\u80fd\u5305\u542b\u5217\u8868\u3001\u5b57\u5178\u7b49\u53ef\u53d8\u7c7b\u578b\u3002<\/li>\n<li>\u53ef\u53d8\u6027&#xff1a;\u652f\u6301\u52a8\u6001\u6dfb\u52a0\u3001\u5220\u9664\u5143\u7d20&#xff08;\u5185\u5b58\u5730\u5740\u4e0d\u53d8&#xff0c;\u5185\u5bb9\u53ef\u53d8&#xff09;\u3002<\/li>\n<\/ul>\n<h5>3. \u57fa\u672c\u64cd\u4f5c<\/h5>\n<h6>&#xff08;1&#xff09;\u6dfb\u52a0\u5143\u7d20<\/h6>\n<ul>\n<li>set.add(value)&#xff1a;\u6dfb\u52a0\u5355\u4e2a\u5143\u7d20&#xff08;\u5143\u7d20\u5df2\u5b58\u5728\u5219\u5ffd\u7565&#xff09;\u3002<\/li>\n<li>set.update(iterable)&#xff1a;\u6dfb\u52a0\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;\u5982\u5217\u8868\u3001\u5143\u7ec4&#xff09;\u4e2d\u7684\u6240\u6709\u5143\u7d20&#xff08;\u81ea\u52a8\u53bb\u91cd&#xff09;\u3002\n<p>s &#061; {1, 2, 3}<br \/>\ns.add(4)  # \u7ed3\u679c&#xff1a;{1, 2, 3, 4}<br \/>\ns.update([3, 4, 5])  # \u6dfb\u52a0\u5217\u8868\u5143\u7d20&#xff0c;\u53bb\u91cd\u540e&#xff1a;{1, 2, 3, 4, 5}<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;2&#xff09;\u5220\u9664\u5143\u7d20<\/h6>\n<ul>\n<li>set.remove(value)&#xff1a;\u5220\u9664\u6307\u5b9a\u5143\u7d20&#xff08;\u5143\u7d20\u4e0d\u5b58\u5728\u5219\u62a5\u9519&#xff09;\u3002<\/li>\n<li>set.discard(value)&#xff1a;\u5220\u9664\u6307\u5b9a\u5143\u7d20&#xff08;\u5143\u7d20\u4e0d\u5b58\u5728\u5219\u5ffd\u7565&#xff0c;\u4e0d\u62a5\u9519&#xff09;\u3002<\/li>\n<li>set.pop()&#xff1a;\u968f\u673a\u5220\u9664\u5e76\u8fd4\u56de\u4e00\u4e2a\u5143\u7d20&#xff08;\u7a7a\u96c6\u5408\u8c03\u7528\u4f1a\u62a5\u9519&#xff09;\u3002<\/li>\n<li>set.clear()&#xff1a;\u6e05\u7a7a\u96c6\u5408\u6240\u6709\u5143\u7d20&#xff08;\u4fdd\u7559\u7a7a\u96c6\u5408&#xff09;\u3002\n<p>s.remove(5)  # \u7ed3\u679c&#xff1a;{1, 2, 3, 4}<br \/>\ns.discard(6)  # \u65e0\u53d8\u5316&#xff08;6\u4e0d\u5b58\u5728&#xff09;<br \/>\nprint(s.pop())  # \u968f\u673a\u8fd4\u56de\u4e00\u4e2a\u5143\u7d20&#xff08;\u59821&#xff09;&#xff0c;\u96c6\u5408\u53d8\u4e3a {2, 3, 4}<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;3&#xff09;\u96c6\u5408\u8fd0\u7b97&#xff08;\u6838\u5fc3\u529f\u80fd&#xff09;<\/h6>\n<ul>\n<li>\u4ea4\u96c6&#xff1a;set1 &amp; set2\u00a0\u6216\u00a0set1.intersection(set2)\u00a0\u2192 \u4e24\u4e2a\u96c6\u5408\u7684\u5171\u540c\u5143\u7d20\u3002<\/li>\n<li>\u5e76\u96c6&#xff1a;set1 | set2\u00a0\u6216\u00a0set1.union(set2)\u00a0\u2192 \u4e24\u4e2a\u96c6\u5408\u7684\u6240\u6709\u5143\u7d20&#xff08;\u53bb\u91cd&#xff09;\u3002<\/li>\n<li>\u5dee\u96c6&#xff1a;set1 &#8211; set2\u00a0\u6216\u00a0set1.difference(set2)\u00a0\u2192 set1 \u6709\u800c set2 \u6ca1\u6709\u7684\u5143\u7d20\u3002<\/li>\n<li>\u5bf9\u79f0\u5dee\u96c6&#xff1a;set1 ^ set2\u00a0\u6216\u00a0set1.symmetric_difference(set2)\u00a0\u2192 \u4e24\u4e2a\u96c6\u5408\u4e2d\u4e92\u4e0d\u76f8\u540c\u7684\u5143\u7d20\u3002\n<p>a &#061; {1, 2, 3}<br \/>\nb &#061; {2, 3, 4}<br \/>\nprint(a &amp; b)  # \u4ea4\u96c6 \u2192 {2, 3}<br \/>\nprint(a | b)  # \u5e76\u96c6 \u2192 {1, 2, 3, 4}<br \/>\nprint(a &#8211; b)  # \u5dee\u96c6 \u2192 {1}<br \/>\nprint(a ^ b)  # \u5bf9\u79f0\u5dee\u96c6 \u2192 {1, 4}<\/p>\n<\/li>\n<\/ul>\n<h6>&#xff08;4&#xff09;\u5176\u4ed6\u57fa\u7840\u64cd\u4f5c<\/h6>\n<ul>\n<li>\u6210\u5458\u5224\u65ad&#xff1a;in\u00a0\/\u00a0not in\u00a0\u5224\u65ad\u5143\u7d20\u662f\u5426\u5728\u96c6\u5408\u4e2d&#xff08;\u6548\u7387\u8fdc\u9ad8\u4e8e\u5217\u8868&#xff09;\u3002\n<p>print(2 in a)  # \u8f93\u51fa True<\/p>\n<\/li>\n<li>\u957f\u5ea6&#xff1a;len(set)\u00a0\u8fd4\u56de\u5143\u7d20\u4e2a\u6570\u3002\n<p>print(len(a))  # \u8f93\u51fa 3<\/p>\n<\/li>\n<\/ul>\n<h5>4. \u5e38\u7528\u65b9\u6cd5<\/h5>\n<table>\n<tr>\u65b9\u6cd5\u4f5c\u7528\u793a\u4f8b\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>add()<\/td>\n<td>\u7528\u4e8e\u5411\u96c6\u5408\u4e2d\u6dfb\u52a0\u5143\u7d20\u3002\u5982\u679c\u5143\u7d20\u5df2\u5b58\u5728&#xff0c;\u5219\u4e0d\u4f1a\u91cd\u590d\u6dfb\u52a0\u3002<\/td>\n<td>thisset &#061; {&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<br \/>\nthisset.add(&#039;d&#039;)<br \/>\nprint(thisset)<\/td>\n<td>{&#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;d&#039;}<\/td>\n<\/tr>\n<tr>\n<td>remove()<\/td>\n<td>\u7528\u4e8e\u79fb\u9664\u96c6\u5408\u4e2d\u7684\u6307\u5b9a\u5143\u7d20\u3002\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4f1a\u5f15\u53d1 KeyError \u5f02\u5e38\u3002<\/td>\n<td>thisset &#061; {&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<br \/>\nthisset.remove(&#039;b&#039;)<br \/>\nprint(thisset)<\/td>\n<td>{&#039;a&#039;, &#039;c&#039;}<\/td>\n<\/tr>\n<tr>\n<td>discard()<\/td>\n<td>\u4e5f\u7528\u4e8e\u79fb\u9664\u96c6\u5408\u4e2d\u7684\u6307\u5b9a\u5143\u7d20&#xff0c;\u4f46\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4e0d\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002<\/td>\n<td>thisset &#061; {&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<br \/>\nthisset.discard(&#039;d&#039;)<br \/>\nprint(thisset)<\/td>\n<td>{&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<\/td>\n<\/tr>\n<tr>\n<td>clear()<\/td>\n<td>\u7528\u4e8e\u6e05\u7a7a\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5143\u7d20&#xff0c;\u5c06\u96c6\u5408\u53d8\u4e3a\u7a7a\u96c6\u3002<\/td>\n<td>thisset &#061; {&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<br \/>\nthisset.clear()<br \/>\nprint(thisset)<\/td>\n<td>set()<\/td>\n<\/tr>\n<tr>\n<td>pop()<\/td>\n<td>\u7528\u4e8e\u968f\u673a\u79fb\u9664\u5e76\u8fd4\u56de\u96c6\u5408\u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u3002\u5982\u679c\u96c6\u5408\u4e3a\u7a7a&#xff0c;\u4f1a\u5f15\u53d1 KeyError \u5f02\u5e38\u3002<\/td>\n<td>thisset &#061; {&#039;a&#039;, &#039;b&#039;, &#039;c&#039;}<br \/>\nremoved_element &#061; thisset.pop()<br \/>\nprint(removed_element)<\/td>\n<td>&#039;a&#039;&#xff08;\u6bcf\u6b21\u7ed3\u679c\u53ef\u80fd\u4e0d\u540c&#xff09;&#8230;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8&#xff1a;\u5217\u8868\u548c\u96c6\u5408\u91cc\u90fd\u6709 pop \u65b9\u6cd5&#xff0c;\u4f46\u884c\u4e3a\u4e0d\u4e00\u6837\u3002\u5217\u8868\u7684 pop \u65b9\u6cd5\u9ed8\u8ba4\u5220\u9664\u5e76\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u96c6\u5408\u7684 pop \u662f\u968f\u673a\u5220\u9664\u5e76\u8fd4\u56de\u4e00\u4e2a\u5143\u7d20\u3002\u5b57\u5178\u91cc\u6ca1\u6709 pop \u65b9\u6cd5&#xff0c;\u4e0d\u8fc7\u6709\u4e2a popitem \u65b9\u6cd5&#xff0c;\u5b83\u662f\u968f\u673a\u5220\u9664\u5e76\u8fd4\u56de\u4e00\u4e2a\u952e\u503c\u5bf9\u3002\u00a0<\/p>\n<h5 style=\"background-color:transparent\">5. \u96c6\u5408\u63a8\u5bfc\u5f0f&#xff08;\u9ad8\u6548\u751f\u6210\u96c6\u5408&#xff09;<\/h5>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;{\u8868\u8fbe\u5f0f for \u53d8\u91cf in \u53ef\u8fed\u4ee3\u5bf9\u8c61 if \u6761\u4ef6}<\/li>\n<li>\u4f5c\u7528&#xff1a;\u5feb\u901f\u751f\u6210\u96c6\u5408&#xff08;\u81ea\u52a8\u53bb\u91cd&#xff09;\u3002\n<p># \u751f\u62101-10\u7684\u5076\u6570\u96c6\u5408<br \/>\nevens &#061; {x for x in range(1, 11) if x % 2 &#061;&#061; 0}<br \/>\nprint(evens)  # \u8f93\u51fa {2, 4, 6, 8, 10}<\/p>\n<p># \u4ece\u5b57\u7b26\u4e32\u63d0\u53d6\u4e0d\u91cd\u590d\u5b57\u7b26<br \/>\nchars &#061; {c for c in &#034;hello world&#034; if c !&#061; &#034; &#034;}<br \/>\nprint(chars)  # \u8f93\u51fa {&#039;h&#039;, &#039;e&#039;, &#039;l&#039;, &#039;o&#039;, &#039;w&#039;, &#039;r&#039;, &#039;d&#039;}&#xff08;\u53bb\u91cd&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h5 style=\"background-color:transparent\">6. \u6ce8\u610f\u4e8b\u9879<\/h5>\n<ul>\n<li>\u65e0\u5e8f\u6027\u5bfc\u81f4\u7684\u4e0d\u53ef\u7d22\u5f15&#xff1a;\u96c6\u5408\u6ca1\u6709\u56fa\u5b9a\u987a\u5e8f&#xff0c;\u4e0d\u80fd\u901a\u8fc7\u7d22\u5f15&#xff08;\u5982\u00a0s[0]&#xff09;\u8bbf\u95ee\u5143\u7d20&#xff0c;\u53ea\u80fd\u901a\u8fc7\u00a0in\u00a0\u5224\u65ad\u662f\u5426\u5b58\u5728&#xff0c;\u6216\u904d\u5386\u5143\u7d20\u3002<\/li>\n<li>\u5143\u7d20\u5fc5\u987b\u53ef\u54c8\u5e0c&#xff1a;\u96c6\u5408\u7684\u5143\u7d20\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff08;\u53ef\u54c8\u5e0c&#xff09;&#xff0c;\u5982\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u7b49\u3002\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\u53ef\u53d8\u7c7b\u578b\u4e0d\u80fd\u4f5c\u4e3a\u96c6\u5408\u5143\u7d20&#xff08;\u4f1a\u62a5\u9519&#xff09;\u3002\n<p>s &#061; {1, &#034;a&#034;, (2, 3)}  # \u5408\u6cd5&#xff08;\u5143\u7d20\u90fd\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b&#xff09;<br \/>\ns &#061; {[1, 2]}  # \u62a5\u9519&#xff08;\u5217\u8868\u662f\u53ef\u53d8\u7c7b\u578b&#xff0c;\u4e0d\u53ef\u54c8\u5e0c&#xff09;<\/p>\n<\/li>\n<li>\u96c6\u5408\u7684\u00a0pop()\u00a0\u65b9\u6cd5\u968f\u673a\u5220\u9664&#xff1a;set.pop()\u00a0\u6ca1\u6709\u53c2\u6570&#xff0c;\u5220\u9664\u7684\u5143\u7d20\u662f\u968f\u673a\u7684&#xff08;\u56e0\u96c6\u5408\u65e0\u5e8f&#xff09;&#xff0c;\u4e0d\u80fd\u6307\u5b9a\u5220\u9664\u67d0\u4e2a\u5143\u7d20&#xff08;\u9700\u7528\u00a0remove\u00a0\u6216\u00a0discard&#xff09;\u3002<\/li>\n<li>\u4e0e\u5b57\u5178\u7684\u8868\u793a\u51b2\u7a81&#xff1a;\u7a7a\u96c6\u5408\u5fc5\u987b\u7528\u00a0set()\u00a0\u8868\u793a&#xff0c;{}\u00a0\u8868\u793a\u7684\u662f\u7a7a\u5b57\u5178&#xff0c;\u800c\u975e\u7a7a\u96c6\u5408\u3002<\/li>\n<li>\u9ad8\u6548\u7684\u6210\u5458\u5224\u65ad&#xff1a;\u96c6\u5408\u7684\u00a0in\u00a0\u64cd\u4f5c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(1)&#xff08;\u8fdc\u5feb\u4e8e\u5217\u8868\u7684\u00a0O(n)&#xff09;&#xff0c;\u9002\u5408\u9700\u8981\u9891\u7e41\u5224\u65ad \u201c\u5143\u7d20\u662f\u5426\u5b58\u5728\u201d \u7684\u573a\u666f&#xff08;\u5982\u53bb\u91cd\u3001\u6570\u636e\u7b5b\u9009&#xff09;\u3002<\/li>\n<li>\u6d45\u62f7\u8d1d\u7279\u6027&#xff1a;\u7528\u00a0set.copy()\u00a0\u6216\u00a0copy.copy()\u00a0\u590d\u5236\u96c6\u5408\u65f6&#xff0c;\u82e5\u96c6\u5408\u4e2d\u5305\u542b\u5d4c\u5957\u7684\u53ef\u53d8\u5bf9\u8c61&#xff08;\u5982\u5143\u7ec4\u5185\u7684\u5217\u8868&#xff0c;\u56e0\u5143\u7ec4\u4e3a\u4e0d\u53ef\u53d8\u5bf9\u8c61&#xff09;&#xff0c;\u6d45\u62f7\u8d1d\u4f1a\u5171\u4eab\u8fd9\u4e9b\u5d4c\u5957\u5bf9\u8c61&#xff08;\u4f46\u96c6\u5408\u672c\u8eab\u7684\u5143\u7d20\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7684&#xff0c;\u6240\u4ee5\u8fd9\u79cd\u60c5\u51b5\u8f83\u5c11\u89c1&#xff09;\u3002<\/li>\n<\/ul>\n<h4>\u00a0\u603b\u7ed3<\/h4>\n<table>\n<tr>\u6570\u636e\u7c7b\u578b\u662f\u5426\u6709\u5e8f\u5143\u7d20\u662f\u5426\u53ef\u91cd\u590d\u5143\u7d20\u662f\u5426\u53ef\u4ee5\u88ab\u53ef\u53d8\u5b9a\u4e49\u7b26\u53f7\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>\u5217\u8868<\/td>\n<td>\u6709\u5e8f<\/td>\n<td>\u53ef\u91cd\u590d<\/td>\n<td>\u53ef\u53d8<\/td>\n<td>[ ]<\/td>\n<td>[1, 2, 3]<\/td>\n<\/tr>\n<tr>\n<td>\u5143\u7ec4<\/td>\n<td>\u6709\u5e8f<\/td>\n<td>\u53ef\u91cd\u590d<\/td>\n<td>\u4e0d\u53ef\u53d8<\/td>\n<td>( )<\/td>\n<td>(1, 2, 3)<\/td>\n<\/tr>\n<tr>\n<td>\u96c6\u5408<\/td>\n<td>\u65e0\u5e8f<\/td>\n<td>\u4e0d\u53ef\u91cd\u590d<\/td>\n<td>\u53ef\u53d8<\/td>\n<td>{ }<\/td>\n<td>{1, 2, 3}<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u5178<\/td>\n<td>\u65e0\u5e8f<\/td>\n<td>\u952e\u4e0d\u53ef\u91cd\u590d&#xff0c;\u503c\u53ef\u91cd\u590d<\/td>\n<td>\u952e\u4e0d\u53ef\u53d8&#xff0c;\u503c\u53ef\u53d8<\/td>\n<td>{ }<\/td>\n<td>{&#034;name&#034;: &#034;Tom&#034;, &#034;age&#034;: 18}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb709\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u5217\u8868\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6709\u5e8f\u3001\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u7cfb\u5217\u5143\u7d20\uff08\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5d4c\u5957\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u3001\u5143\u7ec4\u7b49\uff09\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528[]\u5305\u88f9\u5143\u7d20\uff0c\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\uff0c\u4f8b\u5982\uff1alist1 = [1, 2, 3]  # \u6574\u6570\u5217\u8868list2 = [&quot;a&quot;, 1, True, [4, 5]]  # \u6df7\u5408\u7c7b\u578b\u5217\u8868\uff08\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u3001\u5d4c\u5957\u5217\u8868\uff09empty_list = []  # \u7a7a\u5217\u8868\u5b57\u5178\u662f Python \u4e2d\u952e\u503c\u5bf9\u6620\u5c04\u7684\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u5173\u8054\u578b\u6570\u636e\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528{}\u5305\u88f9\uff0c\u5143\u7d20\u4e3a\u952e: \u503c\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,5261],"topic":[],"class_list":["post-52413","post","type-post","status-publish","format-standard","hentry","category-server","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/52413.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb709\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u5217\u8868\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6709\u5e8f\u3001\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u7cfb\u5217\u5143\u7d20\uff08\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5d4c\u5957\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u3001\u5143\u7ec4\u7b49\uff09\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528[]\u5305\u88f9\u5143\u7d20\uff0c\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\uff0c\u4f8b\u5982\uff1alist1 = [1, 2, 3] # \u6574\u6570\u5217\u8868list2 = [&quot;a&quot;, 1, True, [4, 5]] # \u6df7\u5408\u7c7b\u578b\u5217\u8868\uff08\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u3001\u5d4c\u5957\u5217\u8868\uff09empty_list = [] # \u7a7a\u5217\u8868\u5b57\u5178\u662f Python \u4e2d\u952e\u503c\u5bf9\u6620\u5c04\u7684\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u5173\u8054\u578b\u6570\u636e\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528{}\u5305\u88f9\uff0c\u5143\u7d20\u4e3a\u952e: \u503c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/52413.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-11T06:19:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52413.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/52413.html\",\"name\":\"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-11T06:19:36+00:00\",\"dateModified\":\"2025-08-11T06:19:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/52413.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/52413.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/52413.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/52413.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb709\u6b21\uff0c\u70b9\u8d5e16\u6b21\uff0c\u6536\u85cf13\u6b21\u3002\u5217\u8868\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6709\u5e8f\u3001\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u4e00\u7cfb\u5217\u5143\u7d20\uff08\u5143\u7d20\u53ef\u4ee5\u662f\u4efb\u610f\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5d4c\u5957\u5217\u8868\u3001\u5b57\u5178\u3001\u96c6\u5408\u3001\u5143\u7ec4\u7b49\uff09\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528[]\u5305\u88f9\u5143\u7d20\uff0c\u5143\u7d20\u4e4b\u95f4\u7528\u9017\u53f7\u5206\u9694\uff0c\u4f8b\u5982\uff1alist1 = [1, 2, 3] # \u6574\u6570\u5217\u8868list2 = [&quot;a&quot;, 1, True, [4, 5]] # \u6df7\u5408\u7c7b\u578b\u5217\u8868\uff08\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u3001\u5d4c\u5957\u5217\u8868\uff09empty_list = [] # \u7a7a\u5217\u8868\u5b57\u5178\u662f Python \u4e2d\u952e\u503c\u5bf9\u6620\u5c04\u7684\u53ef\u53d8\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u5173\u8054\u578b\u6570\u636e\u3002\u8868\u793a\u65b9\u5f0f\uff1a\u7528{}\u5305\u88f9\uff0c\u5143\u7d20\u4e3a\u952e: \u503c\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/52413.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-11T06:19:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/52413.html","url":"https:\/\/www.wsisp.com\/helps\/52413.html","name":"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-11T06:19:36+00:00","dateModified":"2025-08-11T06:19:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/52413.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/52413.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/52413.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e00\u6587\u5403\u900f Python \u5217\u8868\u3001\u5b57\u5178\u3001\u5143\u7ec4\u548c\u96c6\u5408\uff0c\u65b0\u624b\u5fc5\u770b\uff01"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=52413"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/52413\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=52413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=52413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=52413"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=52413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}