{"id":14124,"date":"2022-01-20T19:21:19","date_gmt":"2022-01-20T19:21:19","guid":{"rendered":"https:\/\/linuxways.net\/?p=14124"},"modified":"2022-01-20T19:21:19","modified_gmt":"2022-01-20T19:21:19","slug":"find-function-in-python","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/find-function-in-python\/","title":{"rendered":"find() Function in Python"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The find() function in Python is used to check if a substring is in a string according to the start and end values \u200b\u200byou set. This function is almost the same as the index() function.<\/p>\n<p>If present, the function will print the lowest index of that substring. Otherwise, it will return -1.<\/p>\n<p>And the article below, we will show you how to use the find() function in Python through several examples as go through below.<\/p>\n<h2>Example<\/h2>\n<pre>str = \"Welcome to Python\"\r\n\r\nx = str.find(\"to\")\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>8<\/strong><\/p>\n<h2>Definition<\/h2>\n<p>The find() function finds the lowest position of the substring.<\/p>\n<p>If not found, it will return -1.<\/p>\n<h2>The syntax<\/h2>\n<pre>$ string.find(value, start, end)<\/pre>\n<p><strong>Parameter Values<\/strong>:<\/p>\n<p>value: substring that you need to find<\/p>\n<p>start: starting value. Default is 0<\/p>\n<p>end: ending value. Default is the end of the string<\/p>\n<h2>More examples<\/h2>\n<p><strong>Example 1<\/strong>: Find the word &#8220;e&#8221;<\/p>\n<pre>str = \"Welcome to Python\"\r\n\r\nx = str.find(\"l\")\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>1<\/strong><\/p>\n<p><strong>Example 2<\/strong>: Find the word &#8220;e&#8221; from position 3 to position 10<\/p>\n<pre>str = \"Welcome to Python\"\r\n\r\nx = str.find(\"e\", 3, 10)\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>6<\/strong><\/p>\n<p><strong>Example 3<\/strong>: try to find a substring that does not appear<\/p>\n<pre>str = \"Welcome to Python\"\r\n\r\nx = str.find(\"a\")\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>-1<\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>Hope you understand our tutorial on how to use the find() function in Python.<\/p>\n<p>Thanks for reading!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The find() function in Python is used to check if a substring is in a string according to the start and end values \u200b\u200byou set. This function&hellip;<\/p>","protected":false},"author":1,"featured_media":14246,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[860,10],"class_list":["post-14124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-find-function","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14124"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14124\/revisions"}],"predecessor-version":[{"id":14125,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14124\/revisions\/14125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14246"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}