The Python lstrip method is useful for removing the specified characters from the left-hand side of a string. By default, it deletes white spaces and returns a new string. The syntax of the Python lstrip function is
String_Value.lstrip(Chars)
- Chars: This parameter is optional, and Omitting this argument means it considers the white spaces as a default parameter. To change the default white space, please specify the Characters to strip from the left-hand side.
Python lstrip method Example
The following set of examples helps to know the Python lstrip Function.
Str1 = ' Tutorial Gateway' Str2 = Str1.lstrip() print('Stripping Whitespaces on Left is =', Str2) # Observe the Original String print('Converted String is =', Str1.lstrip()) print('Original String is =', Str1) # Performing directly Str3 = '00000000Tutorial Gateway00000000'.lstrip('0') print("Stripping 0's on Left is =", Str3) # Stripping Left Side Str4 = '+++++*********Tutorial Gateway'.lstrip('+*') print('Stripping + and * on Left is =', Str4)

It removes the empty spaces from the left-hand side of the String variable Str1 using this function and prints the output.
Str2 = Str1.lstrip() print('Stripping Whitespaces on Left using LStrip() is =', Str2)
By default, the Python lstrip function returns the output in a new string.
print('Converted String is =', Str1.lstrip()) print('Original String is =', Str1)
To modify the original text, write the following statement.
Str1 = Str1.lstrip()
The lstrip function only removes the specified characters from the left side of a string and omits all the right-hand side characters.
Within the next String function statements, we have zeros on both sides. Moreover, see in the above image that the output removes zeros from the Left-hand side only.
Str3 = '00000000Tutorial Gateway00000000'.lstrip('0') print("Stripping 0's on Left using LStrip() is =", Str3)
In this Python statement, we used two characters to strip (+ and *) from the left-hand side.
Str4 = '+++++*********Tutorial Gateway'.lstrip('+*') print('Stripping + and * on Left using LStrip() is =', Str4)