{"id":902,"date":"2024-11-07T11:59:21","date_gmt":"2024-11-07T03:59:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/902\/"},"modified":"2024-11-07T11:59:21","modified_gmt":"2024-11-07T03:59:21","slug":"python3-%e4%b8%ad-index-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e6%9f%a5%e6%89%be%e5%88%97%e8%a1%a8%e5%85%83%e7%b4%a0%e7%9a%84%e7%b4%a2%e5%bc%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/902\/","title":{"rendered":"Python3 \u4e2d index() \u51fd\u6570\u5982\u4f55\u67e5\u627e\u5217\u8868\u5143\u7d20\u7684\u7d22\u5f15\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1002\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173055854022284.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173055854022284.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173055854022284-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173055854022284-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173055854022284-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Python3 \u4e2d index() \u51fd\u6570\u5982\u4f55\u67e5\u627e\u5217\u8868\u5143\u7d20\u7684\u7d22\u5f15\uff1f\u63d2\u56fe\" alt=\"Python3 \u4e2d index() \u51fd\u6570\u5982\u4f55\u67e5\u627e\u5217\u8868\u5143\u7d20\u7684\u7d22\u5f15\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>python3 \u4e2d index() \u51fd\u6570\u7684\u7528\u6cd5\u8be6\u89e3<\/strong><\/p>\n<p>\u4f7f\u7528 index() \u51fd\u6570\u53ef\u4ee5\u67e5\u627e\u5217\u8868\u4e2d\u67d0\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u8bed\u6cd5\u4e3a\uff1a<\/p>\n<pre>index(value, start=0, stop=len(list))<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cvalue \u662f\u8981\u67e5\u627e\u7684\u5143\u7d20\uff0cstart \u548c stop \u8868\u793a\u9700\u8981\u641c\u7d22\u7684\u8303\u56f4\u3002<\/p>\n<p>\u5728\u7ed9\u5b9a\u7684\u793a\u4f8b\u4e2d\uff0c\u5217\u8868 m \u4e2d\u6709\u591a\u4e2a\u5143\u7d20 4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPython\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<pre>m = [1,2,3,4,34,4,5,6]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>index() \u51fd\u6570\u67e5\u627e\u7b2c\u4e00\u4e2a\u5143\u7d20 4 \u7684\u7d22\u5f15\uff0c\u4ece\u7d22\u5f15 4 \u5230 6 \u4e4b\u95f4\uff0c\u56e0\u6b64\u8fd4\u56de\u7684\u7ed3\u679c\u4e3a 5\uff1a<\/p>\n<pre>n = m.index(4, 4, 6)\nprint(n)  # \u8f93\u51fa 5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5143\u7d20 4 \u4f4d\u4e8e\u7d22\u5f15 5 \u5904\uff0c\u5b83\u6ee1\u8db3\u5728\u7d22\u5f15 4 \u5230 6 \u4e4b\u95f4\u67e5\u627e\u5143\u7d20 4 \u7684\u6761\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPython3 \u4e2d index() \u51fd\u6570\u5982\u4f55\u67e5\u627e\u5217\u8868\u5143\u7d20\u7684\u7d22\u5f15\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>python3 \u4e2d index() \u51fd\u6570\u7684\u7528\u6cd5\u8be6\u89e3 \u4f7f\u7528 index() \u51fd\u6570\u53ef\u4ee5\u67e5\u627e\u5217\u8868\u4e2d\u67d0\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u8bed\u6cd5\u4e3a\uff1a index(value, start=0, stop=len(list)) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cvalue \u662f\u8981\u67e5\u627e\u7684\u5143\u7d20\uff0cstart \u548c stop \u8868\u793a\u9700\u8981\u641c\u7d22\u7684\u8303\u56f4\u3002 \u5728\u7ed9\u5b9a\u7684\u793a\u4f8b\u4e2d\uff0c\u5217\u8868 m \u4e2d\u6709\u591a\u4e2a\u5143\u7d20 4\uff1a \u7acb\u5373\u5b66\u4e60\u201cPython\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b m = [1,2,3,4,34,4,5,6] \u767b\u5f55\u540e\u590d\u5236 index() \u51fd\u6570\u67e5\u627e\u7b2c\u4e00\u4e2a\u5143\u7d20 4 \u7684\u7d22\u5f15\uff0c\u4ece\u7d22\u5f15 4 \u5230 6 \u4e4b\u95f4\uff0c\u56e0\u6b64\u8fd4\u56de\u7684\u7ed3\u679c\u4e3a 5\uff1a n = m.index(4, 4, 6) print(n) # \u8f93\u51fa 5 \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u662f\u56e0\u4e3a\u7b2c\u4e00\u4e2a\u5143\u7d20 4 \u4f4d\u4e8e\u7d22\u5f15 5 \u5904\uff0c\u5b83\u6ee1\u8db3\u5728\u7d22\u5f15 4 \u5230 6 \u4e4b\u95f4\u67e5\u627e\u5143\u7d20 4 \u7684\u6761\u4ef6\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-902","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=902"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/902\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}