{"id":3685,"date":"2022-12-02T18:33:44","date_gmt":"2022-12-02T18:33:44","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3685"},"modified":"2022-12-02T18:33:46","modified_gmt":"2022-12-02T18:33:46","slug":"python-string-lstrip","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-lstrip\/","title":{"rendered":"Python String lstrip() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String lstrip<\/p>\n<p>Now, we are going to learn about the lstrip method. Using this method, we get a copy of the string, with the leading characters removed. We can provide a string as an argument, specifying the set of characters to be removed from the left of the string. If we do not specify the argument string, it defaults to removing the whitespaces. 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-3686 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD.jpg\" alt=\"\" width=\"635\" height=\"71\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD.jpg 635w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-300x34.jpg 300w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String lstrip() Method<\/h2>\n<p>As you can see in the above program, we have a string, where we have some hyphen signs at the beginning and end of the string. Then, we are calling the lstrip method, and we specified the hyphen sign as the argument string, to be removed from the left of the string. So, in the output, you can see all the leading hyphen signs removed, and the copy of the string is returned. Let\u2019s have a look at the output as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3687 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-1.jpg\" alt=\"\" width=\"628\" height=\"85\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-1.jpg 628w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-1-300x41.jpg 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/p>\n<p>GyaniPandit&#8212;&#8211;<\/p>\n<p>As you can see in the output, we got the string with the leading characters removed. So, as and when required, we can make use of the lstrip method, remember that this method returns the copy of the string, with the leading characters removed.<\/p>\n<p>If we do not specify the string specifying the characters to be removed, then it defaults to remove the whitespace. 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-3688 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-2.jpg\" alt=\"\" width=\"645\" height=\"78\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-2.jpg 645w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-lstrip-METHOD-2-300x36.jpg 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<p>As you can see in the above program, we have a string, with some leading and trailing whitespaces, and then we are calling the lstrip method on the string. If you try to execute the program, you can simply find that we get a string, with the leading whitespaces removed, since we had not specified the string argument. You can try to execute the program and observe the output.<\/p>\n<p>So, as and when required, we can make use of the lstrip method in our programs. Remember that the method returns the string with the leading characters\/whitespaces removed. The original string is still as it was.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String lstrip Now, we are going to learn about the lstrip method. Using this method, we get a copy of the string, with the leading characters removed. We can provide a string as an argument, specifying the set of characters to be removed from the left of the string. If we do not specify [&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-3685","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\/3685","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=3685"}],"version-history":[{"count":3,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3685\/revisions"}],"predecessor-version":[{"id":4190,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3685\/revisions\/4190"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}