{"id":194,"date":"2023-02-22T22:14:23","date_gmt":"2023-02-22T14:14:23","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=194"},"modified":"2023-02-22T22:27:48","modified_gmt":"2023-02-22T14:27:48","slug":"python-determine-whether-string-contains-substring","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/22\/python-determine-whether-string-contains-substring\/","title":{"rendered":"Python\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32"},"content":{"rendered":"<h2>in<\/h2>\n<pre><code class=\"language-python\">string = &#039;hello world&#039;\nif &#039;world&#039; in string:\n    print &#039;Exist&#039;\nelse:\n    print &#039;Not exist&#039;<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>find<\/h2>\n<pre><code class=\"language-python\">string = &#039;hello world&#039;\nif string.find(&#039;world&#039;) == 6:  # 6\u7684\u610f\u601d\u662fworld\u5b57\u7b26\u4ece\u54ea\u4e2a\u5e8f\u5f00\u59cb\uff0c\u56e0\u4e3aw\u4f4d\u4e8e\u7b2c6\u4e2a\uff0c\u5373\u5e8f\u4e3a6\n    print &#039;Exist&#039;\nelse:\n    print &#039;Not exist&#039;<\/code><\/pre>\n<h2>index<\/h2>\n<p>\u6b64\u65b9\u6cd5\u4e0efind\u4f5c\u7528\u7c7b\u4f3c\uff0c\u4e5f\u662f\u627e\u5230\u5b57\u7b26\u8d77\u59cb\u7684\u5e8f\u53f7\u3002\u5982\u679c\u6ca1\u627e\u5230\uff0c\u7a0b\u5e8f\u4f1a\u629b\u51fa\u5f02\u5e38<\/p>\n<pre><code class=\"language-python\">string = &#039;hello world&#039;\nif string.index(&#039;world&#039;) &gt; -1:  # \u56e0\u4e3a-1\u7684\u610f\u601d\u4ee3\u8868\u6ca1\u6709\u627e\u5230\u5b57\u7b26\uff0c\u6240\u4ee5\u5224\u65ad&gt;-1\u5c31\u4ee3\u8868\u53ef\u4ee5\u627e\u5230\n    print &#039;Exist&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>in string = &#039;hello world&#039; if &#039;world&#038;#039 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}