{"id":204311,"date":"2025-05-29T12:55:11","date_gmt":"2025-05-29T04:55:11","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204311\/"},"modified":"2025-05-29T12:55:11","modified_gmt":"2025-05-29T04:55:11","slug":"python3-%e4%b8%ad-index-%e5%87%bd%e6%95%b0%e7%9a%84-start-%e5%92%8c-end-%e5%8f%82%e6%95%b0%e5%a6%82%e4%bd%95%e5%bd%b1%e5%93%8d%e6%90%9c%e7%b4%a2%e7%bb%93%e6%9e%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204311\/","title":{"rendered":"Python3 \u4e2d index() \u51fd\u6570\u7684 start \u548c end \u53c2\u6570\u5982\u4f55\u5f71\u54cd\u641c\u7d22\u7ed3\u679c\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python3 \u4e2d index() \u51fd\u6570\u7684 start \u548c end \u53c2\u6570\u5982\u4f55\u5f71\u54cd\u641c\u7d22\u7ed3\u679c\uff1f<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython3 \u4e2d index() \u51fd\u6570\u7684 start \u548c end \u53c2\u6570\u5982\u4f55\u5f71\u54cd\u641c\u7d22\u7ed3\u679c\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241104\/1730685099672828abb92d7.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python3 index() \u51fd\u6570\u7684\u7591\u70b9<\/strong><\/p>\n<p>python3 \u4e2d\u7684 index() \u51fd\u6570\u7528\u4e8e\u5728\u7ed9\u5b9a\u5e8f\u5217\u4e2d\u67e5\u627e\u5143\u7d20\u7684\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u7684\u7d22\u5f15\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5b83\u7684\u884c\u4e3a\u53ef\u80fd\u4f1a\u5f15\u8d77\u56f0\u60d1\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>m = [1, 2, 3, 4, 34, 4, 5, 6]\nn = m.index(4, 4, 6)\nprint(n)<\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>5<\/pre>\n<p><strong>\u7591\u95ee\uff1a<\/strong><\/p>\n<p>\u4e3a\u4ec0\u4e48\u8f93\u51fa\u7ed3\u679c\u662f 5\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>index() \u51fd\u6570\u7684\u8bed\u6cd5\u4e3a index(element, start=0, end=len(sequence))\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06 start \u53c2\u6570\u8bbe\u7f6e\u4e3a 4\uff0c\u8868\u793a\u4ece\u5e8f\u5217\u4e2d\u7d22\u5f15\u4e3a 4 \u7684\u5143\u7d20\u5f00\u59cb\u641c\u7d22\u3002end \u53c2\u6570\u8bbe\u7f6e\u4e3a 6\uff0c\u8868\u793a\u641c\u7d22\u8303\u56f4\u7ed3\u675f\u4e8e\u7d22\u5f15\u4e3a 6 \u7684\u5143\u7d20\u4e4b\u524d\u3002\u56e0\u6b64\uff0c\u51fd\u6570\u5c06\u5728\u7d22\u5f15 4 \u5230 6 \u4e4b\u95f4\u641c\u7d22\u5143\u7d20 4\u3002<\/p>\n<p>\u8be5\u5e8f\u5217\u4e2d\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u662f\u7d22\u5f15\u4e3a 5 \u7684\u5143\u7d20\uff0c\u56e0\u6b64\u51fd\u6570\u8fd4\u56de 5\u3002\u56e0\u6b64\uff0c\u8f93\u51fa\u7ed3\u679c\u5408\u7406\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aPython3 \u4e2d index() \u51fd\u6570\u7684 start \u548c end \u53c2\u6570\u5982\u4f55\u5f71\u54cd\u641c\u7d22\u7ed3\u679c\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python3 \u4e2d index(&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204311","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204311"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204311\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}