{"id":12582,"date":"2021-06-09T22:03:24","date_gmt":"2021-06-10T03:03:24","guid":{"rendered":"httpss:\/\/www.powenko.com\/wordpress\/docs\/python\/%e5%ad%97%e4%b8%b2\/%e6%89%be%e5%ad%97%e4%b8%b2find\/"},"modified":"2021-06-09T22:16:57","modified_gmt":"2021-06-10T03:16:57","slug":"%e6%89%be%e5%ad%97%e4%b8%b2find","status":"publish","type":"docs","link":"https:\/\/www.powenko.com\/wordpress\/?docs=python\/%e5%ad%97%e4%b8%b2\/%e6%89%be%e5%ad%97%e4%b8%b2find","title":{"rendered":"\u627e\u5b57\u4e32find"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxt = &quot;\/2018\/04\/23\/running-keras-models-on-ios-with-coreml\/&quot;\r\nx = txt.find(&quot;\/20&quot;)\r\nprint(x) #0\r\n<\/pre>\n<p>\u8f38\u51fa<br \/>\n0<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntxt = &quot;\/2018\/04\/23\/running-keras-models-on-ios-with-coreml\/&quot;\r\nx = txt.find(&quot;\/20&quot;)\r\nprint(x)\r\nx = txt.find(&quot;running&quot;)\r\nprint(x)\r\nx = txt.find(&quot;\/&quot;)\r\nprint(x)\r\nx = txt.find(&quot;powenko&quot;)\r\nprint(x)\r\n<\/pre>\n<p>\u8f38\u51fa<br \/>\n0<br \/>\n12<br \/>\n0<br \/>\n-1<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ntext = &quot;John got up. John went to the cinema. John washed his hand.&quot;\r\npos = -1 \r\nwhile True:\r\n    pos = text.find('John', pos + 1)\r\n    if pos == -1:\r\n        break\r\n    print(text&#x5B;:pos]) \r\n\r\nprint(&quot;-----&quot;)\r\npos = -1\r\nwhile True:\r\n    pos = text.find('John', pos + 1)\r\n    if pos == -1:\r\n        break\r\n    print(text&#x5B;pos:])     \r\n<\/pre>\n<p>\u8f38\u51fa\uff1a<br \/>\nJohn got up.<br \/>\nJohn got up. John went to the cinema.<br \/>\n&#8212;&#8211;<br \/>\nJohn got up. John went to the cinema. John washed his hand.<br \/>\nJohn went to the cinema. John washed his hand.<br \/>\nJohn washed his hand.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nsentence = 'abc1 abc2 abc3 abc4 abc5'\r\n \r\nprint(sentence.index('a', 10))\r\n \r\nprint(sentence.index('a', 10, -4))\r\n \r\nprint(sentence.index('a', 7, 18))\r\n\r\n<\/pre>\n<p>\u8f38\u51fa<\/p>\n<p>10<br \/>\n10<br \/>\n10<\/p>\n","protected":false},"featured_media":0,"parent":12565,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-12582","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12582"}],"collection":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12582"}],"version-history":[{"count":7,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12582\/revisions"}],"predecessor-version":[{"id":12594,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12582\/revisions\/12594"}],"up":[{"embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12565"}],"next":[{"title":"\u53d6\u5f97\u4e2d\u9593\u7684\u6587\u5b57","link":"https:\/\/www.powenko.com\/wordpress\/?docs=python\/%e5%ad%97%e4%b8%b2\/%e5%8f%96%e7%9a%84%e4%b8%ad%e9%96%93%e7%9a%84%e6%96%87%e5%ad%97","href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=\/wp\/v2\/docs\/12588"}],"wp:attachment":[{"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12582"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.powenko.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fdoc_tag&post=12582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}