{"id":3269,"date":"2018-03-27T15:05:53","date_gmt":"2018-03-27T07:05:53","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=3269"},"modified":"2018-03-27T15:05:53","modified_gmt":"2018-03-27T07:05:53","slug":"python-%e5%88%97%e8%a1%a8list%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/python-%e5%88%97%e8%a1%a8list%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3\/","title":{"rendered":"Python \u5217\u8868(List)\u64cd\u4f5c\u65b9\u6cd5\u8be6\u89e3"},"content":{"rendered":"<div class=\"art_desc mt10\">\n<div id=\"art_demo\">\n<div id=\"art_demo\">\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Python\u4e2d\u5217\u8868(List)\u7684\u8be6\u89e3\u64cd\u4f5c\u65b9\u6cd5,\u5305\u542b\u521b\u5efa\u3001\u8bbf\u95ee\u3001\u66f4\u65b0\u3001\u5220\u9664\u3001\u5176\u5b83\u64cd\u4f5c\u7b49,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/div>\n<\/div>\n<\/div>\n<div class=\"lbd clearfix\"><\/div>\n<div id=\"content\">\n<p>\u5217\u8868\u662fPython\u4e2d\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5217\u8868\u662f\u6700\u5e38\u7528\u7684Python\u6570\u636e\u7c7b\u578b\uff0c\u5217\u8868\u7684\u6570\u636e\u9879\u4e0d\u9700\u8981\u5177\u6709\u76f8\u540c\u7684\u7c7b\u578b\u3002\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u5206\u914d\u4e00\u4e2a\u6570\u5b57 &#8211; \u5b83\u7684\u4f4d\u7f6e\uff0c\u6216\u7d22\u5f15\uff0c\u7b2c\u4e00\u4e2a\u7d22\u5f15\u662f0\uff0c\u7b2c\u4e8c\u4e2a\u7d22\u5f15\u662f1\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<br \/>\nPython\u67096\u4e2a\u5e8f\u5217\u7684\u5185\u7f6e\u7c7b\u578b\uff0c\u4f46\u6700\u5e38\u89c1\u7684\u662f\u5217\u8868\u548c\u5143\u7ec4\u3002\u5e8f\u5217\u90fd\u53ef\u4ee5\u8fdb\u884c\u7684\u64cd\u4f5c\u5305\u62ec\u7d22\u5f15\uff0c\u5207\u7247\uff0c\u52a0\uff0c\u4e58\uff0c\u68c0\u67e5\u6210\u5458\u3002\u6b64\u5916\uff0cPython\u5df2\u7ecf\u5185\u7f6e\u786e\u5b9a\u5e8f\u5217\u7684\u957f\u5ea6\u4ee5\u53ca\u786e\u5b9a\u6700\u5927\u548c\u6700\u5c0f\u7684\u5143\u7d20\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u4e00\u3001\u521b\u5efa\u4e00\u4e2a\u5217\u8868<br \/>\n<\/strong>\u53ea\u8981\u628a\u9017\u53f7\u5206\u9694\u7684\u4e0d\u540c\u7684\u6570\u636e\u9879\u4f7f\u7528\u65b9\u62ec\u53f7\u62ec\u8d77\u6765\u5373\u53ef\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut34020\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code34020\" class=\"codebody\">list1 = [&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000];<br \/>\nlist2 = [1, 2, 3, 4, 5 ];<br \/>\nlist3 = [&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, &#8220;d&#8221;];<\/div>\n<p>\u4e0e\u5b57\u7b26\u4e32\u7684\u7d22\u5f15\u4e00\u6837\uff0c\u5217\u8868\u7d22\u5f15\u4ece0\u5f00\u59cb\u3002\u5217\u8868\u53ef\u4ee5\u8fdb\u884c\u622a\u53d6\u3001\u7ec4\u5408\u7b49\u3002<br \/>\n<strong>\u4e8c\u3001\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u503c<\/strong><br \/>\n\u4f7f\u7528\u4e0b\u6807\u7d22\u5f15\u6765\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u503c\uff0c\u540c\u6837\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7\u7684\u5f62\u5f0f\u622a\u53d6\u5b57\u7b26\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut25734\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code25734\" class=\"codebody\">#!\/usr\/bin\/python<\/p>\n<p>list1 = [&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000];<br \/>\nlist2 = [1, 2, 3, 4, 5, 6, 7 ];print &#8220;list1[0]: &#8220;, list1[0]<br \/>\nprint &#8220;list2[1:5]: &#8220;, list2[1:5]<\/p>\n<\/div>\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut3708\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code3708\" class=\"codebody\">list1[0]:\u00a0 physics<br \/>\nlist2[1:5]:\u00a0 [2, 3, 4, 5]<\/div>\n<p><strong>\u4e09\u3001\u66f4\u65b0\u5217\u8868<\/strong><br \/>\n\u4f60\u53ef\u4ee5\u5bf9\u5217\u8868\u7684\u6570\u636e\u9879\u8fdb\u884c\u4fee\u6539\u6216\u66f4\u65b0\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528append()\u65b9\u6cd5\u6765\u6dfb\u52a0\u5217\u8868\u9879\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut43229\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code43229\" class=\"codebody\">#!\/usr\/bin\/pythonlist = [&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000];<\/p>\n<p>print &#8220;Value available at index 2 : &#8221;<br \/>\nprint list[2];<br \/>\nlist[2] = 2001;<br \/>\nprint &#8220;New value available at index 2 : &#8221;<br \/>\nprint list[2];<\/p>\n<\/div>\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut24666\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code24666\" class=\"codebody\">Value available at index 2 :<br \/>\n1997<br \/>\nNew value available at index 2 :<br \/>\n2001<\/div>\n<p><strong>\u56db\u3001\u5220\u9664\u5217\u8868\u5143\u7d20<\/strong><br \/>\n\u53ef\u4ee5\u4f7f\u7528 del \u8bed\u53e5\u6765\u5220\u9664\u5217\u8868\u7684\u7684\u5143\u7d20\uff0c\u5982\u4e0b\u5b9e\u4f8b\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut6912\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code6912\" class=\"codebody\">#!\/usr\/bin\/pythonlist1 = [&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000];<\/p>\n<p>print list1;<br \/>\ndel list1[2];<br \/>\nprint &#8220;After deleting value at index 2 : &#8221;<br \/>\nprint list1;<\/p>\n<\/div>\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut33616\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code33616\" class=\"codebody\">[&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000]<br \/>\nAfter deleting value at index 2 :<br \/>\n[&#8216;physics&#8217;, &#8216;chemistry&#8217;, 2000]<\/div>\n<p><strong>\u4e94\u3001Python\u5217\u8868\u811a\u672c\u64cd\u4f5c\u7b26<br \/>\n<\/strong>\u5217\u8868\u5bf9 + \u548c * \u7684\u64cd\u4f5c\u7b26\u4e0e\u5b57\u7b26\u4e32\u76f8\u4f3c\u3002+ \u53f7\u7528\u4e8e\u7ec4\u5408\u5217\u8868\uff0c* \u53f7\u7528\u4e8e\u91cd\u590d\u5217\u8868\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<th>Python \u8868\u8fbe\u5f0f<\/th>\n<th>\u7ed3\u679c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td>len([1, 2, 3])<\/td>\n<td>3<\/td>\n<td>\u957f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>[1, 2, 3] + [4, 5, 6]<\/td>\n<td>[1, 2, 3, 4, 5, 6]<\/td>\n<td>\u7ec4\u5408<\/td>\n<\/tr>\n<tr>\n<td>[&#8216;Hi!&#8217;] * 4<\/td>\n<td>[&#8216;Hi!&#8217;, &#8216;Hi!&#8217;, &#8216;Hi!&#8217;, &#8216;Hi!&#8217;]<\/td>\n<td>\u91cd\u590d<\/td>\n<\/tr>\n<tr>\n<td>3 in [1, 2, 3]<\/td>\n<td>True<\/td>\n<td>\u5143\u7d20\u662f\u5426\u5b58\u5728\u4e8e\u5217\u8868\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>for x in [1, 2, 3]: print x,<\/td>\n<td>1 2 3<\/td>\n<td>\u8fed\u4ee3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u516d\u3001Python\u5217\u8868\u622a\u53d6<\/strong><br \/>\nPython\u7684\u5217\u8868\u622a\u53d6\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u7c7b\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<div class=\"codetitle\"><a id=\"copybut53506\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code53506\" class=\"codebody\">L = [&#8216;spam&#8217;, &#8216;Spam&#8217;, &#8216;SPAM!&#8217;]<\/div>\n<p>\u64cd\u4f5c\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<th>Python \u8868\u8fbe\u5f0f<\/th>\n<th>\u7ed3\u679c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td>L[2]<\/td>\n<td>&#8216;SPAM!&#8217;<\/td>\n<td>\u8bfb\u53d6\u5217\u8868\u4e2d\u7b2c\u4e09\u4e2a\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td>L[-2]<\/td>\n<td>&#8216;Spam&#8217;<\/td>\n<td>\u8bfb\u53d6\u5217\u8868\u4e2d\u5012\u6570\u7b2c\u4e8c\u4e2a\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td>L[1:]<\/td>\n<td>[&#8216;Spam&#8217;, &#8216;SPAM!&#8217;]<\/td>\n<td>\u4ece\u7b2c\u4e8c\u4e2a\u5143\u7d20\u5f00\u59cb\u622a\u53d6\u5217\u8868<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u4e03\u3001Python\u5217\u8868\u64cd\u4f5c\u7684\u51fd\u6570\u548c\u65b9\u6cd5<br \/>\n\u5217\u8868\u64cd\u4f5c\u5305\u542b\u4ee5\u4e0b\u51fd\u6570:<br \/>\n<\/strong>1\u3001cmp(list1, list2)\uff1a\u6bd4\u8f83\u4e24\u4e2a\u5217\u8868\u7684\u5143\u7d20<br \/>\n2\u3001len(list)\uff1a\u5217\u8868\u5143\u7d20\u4e2a\u6570<br \/>\n3\u3001max(list)\uff1a\u8fd4\u56de\u5217\u8868\u5143\u7d20\u6700\u5927\u503c<br \/>\n4\u3001min(list)\uff1a\u8fd4\u56de\u5217\u8868\u5143\u7d20\u6700\u5c0f\u503c<br \/>\n5\u3001list(seq)\uff1a\u5c06\u5143\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868<br \/>\n<strong>\u5217\u8868\u64cd\u4f5c\u5305\u542b\u4ee5\u4e0b\u65b9\u6cd5:<br \/>\n<\/strong>1\u3001list.append(obj)\uff1a\u5728\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u65b0\u7684\u5bf9\u8c61<br \/>\n2\u3001list.count(obj)\uff1a\u7edf\u8ba1\u67d0\u4e2a\u5143\u7d20\u5728\u5217\u8868\u4e2d\u51fa\u73b0\u7684\u6b21\u6570<br \/>\n3\u3001list.extend(seq)\uff1a\u5728\u5217\u8868\u672b\u5c3e\u4e00\u6b21\u6027\u8ffd\u52a0\u53e6\u4e00\u4e2a\u5e8f\u5217\u4e2d\u7684\u591a\u4e2a\u503c\uff08\u7528\u65b0\u5217\u8868\u6269\u5c55\u539f\u6765\u7684\u5217\u8868\uff09<br \/>\n4\u3001list.index(obj)\uff1a\u4ece\u5217\u8868\u4e2d\u627e\u51fa\u67d0\u4e2a\u503c\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u7684\u7d22\u5f15\u4f4d\u7f6e<br \/>\n5\u3001list.insert(index, obj)\uff1a\u5c06\u5bf9\u8c61\u63d2\u5165\u5217\u8868<br \/>\n6\u3001list.pop(obj=list[-1])\uff1a\u79fb\u9664\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\uff08\u9ed8\u8ba4\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u5e76\u4e14\u8fd4\u56de\u8be5\u5143\u7d20\u7684\u503c<br \/>\n7\u3001list.remove(obj)\uff1a\u79fb\u9664\u5217\u8868\u4e2d\u67d0\u4e2a\u503c\u7684\u7b2c\u4e00\u4e2a\u5339\u914d\u9879<br \/>\n8\u3001list.reverse()\uff1a\u53cd\u5411\u5217\u8868\u4e2d\u5143\u7d20<br \/>\n9\u3001list.sort([func])\uff1a\u5bf9\u539f\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Python\u4e2d\u5217\u8868(List)\u7684\u8be6\u89e3\u64cd\u4f5c\u65b9\u6cd5,\u5305\u542b\u521b\u5efa\u3001\u8bbf\u95ee\u3001\u66f4\u65b0\u3001\u5220\u9664\u3001\u5176\u5b83\u64cd\u4f5c\u7b49,\u9700\u8981\u7684 &#8230; <a title=\"Python \u5217\u8868(List)\u64cd\u4f5c\u65b9\u6cd5\u8be6\u89e3\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/python-%e5%88%97%e8%a1%a8list%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e8%af%a6%e8%a7%a3\/\" aria-label=\"\u9605\u8bfb Python \u5217\u8868(List)\u64cd\u4f5c\u65b9\u6cd5\u8be6\u89e3\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[654,5],"tags":[],"class_list":["post-3269","post","type-post","status-publish","format-standard","hentry","category-python","category-jishu"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=3269"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3269\/revisions"}],"predecessor-version":[{"id":3270,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3269\/revisions\/3270"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=3269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=3269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=3269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}