We use the strip() method to remove unwanted whitespaces or characters/strings from both sides of the given string. What if we want to remove them from only one side? We can use lstrip() and rstrip() methods to serve this purpose. We use the lstrip() method to remove unwanted whitespaces or characters/strings from the given string’s left-side position. And the rstrip() method is used to remove unwanted whitespaces or characters/strings from the given string’s right side.
Table of Contents
Syntax of the lstrip() Method
string.lstrip([character])
Syntax of the rstrip() Method
string.rstrip([character])
Example: lstrip() Method
Code
string = "!Welcome to Code Leaks!"
striped_string = string.lstrip("!")
print(striped_string)
Output

Example: rstrip() Method
Code:
string = "!Welcome to Code Leaks!"
striped_string = string.rstrip()
print(striped_string)
Output

Conclusion
In this article, we discussed the lstrip() and rstrip() methods in Python, which we use to remove unwanted whitespaces/characters/string from a given string either from the left or right. The lstrip() method removes it from the string’s left side, and the rstrip() method removes it from the right side of the string.