{"id":3708,"date":"2022-12-02T18:47:19","date_gmt":"2022-12-02T18:47:19","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3708"},"modified":"2022-12-02T18:47:20","modified_gmt":"2022-12-02T18:47:20","slug":"python-string-rsplit","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-rsplit\/","title":{"rendered":"Python String rsplit() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String rsplit<\/p>\n<p>Now, we are going to learn about the rsplit method. This method split\u2019s the string from the right, on the specified separator, and it returns a list of the strings. If we are not providing the separator, then it defaults to whitespace. 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-3709 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD.jpg\" alt=\"\" width=\"631\" height=\"89\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD.jpg 631w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-300x42.jpg 300w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String rsplit() Method<\/h2>\n<p>As you can see in the above program, we have a string, where we have different items. Then we are calling the rsplit method, and we have specified &#8216;, &#8216; as the separator. So, the rsplit returns a list of strings, separated on the given separator. Let\u2019s have a look at the output now.<\/p>\n<p>[&#8216;Sugar&#8217;, &#8216;Wheat&#8217;, &#8216;Rice&#8217;, &#8216;Butter&#8217;, &#8216;Cheese&#8217;]<\/p>\n<p>As you can see in the output, we have a list of strings, separated at the given separator. If the separator is not specified, the separator is considered as the whitespace. Let\u2019s have a look at another example, where we would not specify the separator as an argument to the rsplit method. Let\u2019s have a look at the program.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3710 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-1.jpg\" alt=\"\" width=\"619\" height=\"100\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-1.jpg 619w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-1-300x48.jpg 300w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><\/p>\n<p>As you can see in the above program, we have a string, and then we are calling the rsplit method on the string. Basically, we are not giving any separator here, so it would be considered as the whitespace. So, we get a list of strings, separated on the whitespace. Let\u2019s have a look at the output now.<\/p>\n<p>[&#8216;Hello&#8217;, &#8216;from&#8217;, &#8216;GyaniPandit&#8217;]<\/p>\n<p>As you can see in the output, we have the list of strings, separated at the whitespace. So, when we are not specifying the separator as an argument, it is considered as the whitespace.<\/p>\n<p>Also, we can provide another optional argument, which is maxsplit, which specifies the number of times, the split\u2019s are done. Let\u2019s have a look at a simple program, which tries to demonstrate the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3711 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-2.jpg\" alt=\"\" width=\"625\" height=\"81\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-2.jpg 625w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-rsplit-METHOD-2-300x39.jpg 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/p>\n<p>As you can see in the above program, we have a string, and then we are trying to call the rsplit method on the string. We have specified the separator, and this time, we also have specified the maxsplit argument, due to which, the split\u2019s will be done 3 times. Let\u2019s have a look at the output now.<\/p>\n<p>[&#8216;Sugar, Wheat&#8217;, &#8216;Rice&#8217;, &#8216;Butter&#8217;, &#8216;Cheese&#8217;]<\/p>\n<p>As you can see in the output, we got a list of strings, and the splits were done 3 times. So, as and when required, we can make use of the rsplit method in our python programs. Remember that the rsplit method split\u2019s the string on the specified separator, and it returns the list of strings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String rsplit Now, we are going to learn about the rsplit method. This method split\u2019s the string from the right, on the specified separator, and it returns a list of the strings. If we are not providing the separator, then it defaults to whitespace. Let\u2019s have a look at a simple program, which demonstrates [&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-3708","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\/3708","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=3708"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3708\/revisions"}],"predecessor-version":[{"id":4197,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3708\/revisions\/4197"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}