{"id":3703,"date":"2022-12-02T18:45:28","date_gmt":"2022-12-02T18:45:28","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3703"},"modified":"2022-12-02T18:45:29","modified_gmt":"2022-12-02T18:45:29","slug":"python-string-rfind","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-rfind\/","title":{"rendered":"Python String rfind() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String rfind<\/p>\n<p>Now, we are going to learn about the rfind method. With this method, we can get the highest index, where the given substring is found. If the substring is not found, then -1 is returned. Let\u2019s have a look at a simple program, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3704 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD.jpg\" alt=\"\" width=\"633\" height=\"62\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD.jpg 633w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-300x29.jpg 300w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String rfind() Method<\/h2>\n<p>As you can see in the above program, we have the string, and then we are trying to call the rfind method. The rfind method is going to return the highest index of the given substring if the substring is found, and else it returns -1. In this case, the output from the method is 27, which is the highest index where the string is found.<\/p>\n<p>Let\u2019s consider a case now, in which we are going to give such a string as an input to the rfind method, which does not exist in the string. Let\u2019s see the output in this case.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3705 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-1.jpg\" alt=\"\" width=\"635\" height=\"68\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-1.jpg 635w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-1-300x32.jpg 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<p>As you can see in the above program, we have a simple string, and then we are calling the rfind method, and we are passing a string as the input to the rfind method, which is not found in the given string. In such a case, we get the output as -1. You can try executing the program and observing the output.<\/p>\n<p>We can also give some optional start and end indexes, specifying a range to search for. Let\u2019s have a look at a simple example, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3706 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-2.jpg\" alt=\"\" width=\"633\" height=\"67\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-2.jpg 633w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rfind-METHOD-2-300x32.jpg 300w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/p>\n<p>As you can see in the above program, we have a simple string, and then we are calling the rfind method. We are passing the string, the start, and the end arguments to the method. So, the rfind method is going to return the highest index where the given substring is found in the given range. If you try to execute the program and observe the output from the program, it comes out to be 0.<\/p>\n<p>So, as and when required, we can make use of the rfind method, to get the highest index of the given substring in the string, if found. If not found, the method returns -1.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String rfind Now, we are going to learn about the rfind method. With this method, we can get the highest index, where the given substring is found. If the substring is not found, then -1 is returned. Let\u2019s have a look at a simple program, which demonstrates the same thing. Python String rfind() Method [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3703","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3703"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3703\/revisions"}],"predecessor-version":[{"id":4196,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3703\/revisions\/4196"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}