The lstrip() method cuts off spaces or specified characters at the left of a string.
Example
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
str = " have a nice day!"
print(str)
# remove spaces on the left
strnew = str.lstrip()
print(strnew)
# remove characters on the left
print(strnew.lstrip('have'))
Output:
have a nice day!
have a nice day!
a nice day!
Syntax
string.rstrip([chars])
Parameters
Name | Description |
chars | A string specifying the set of characters to be removed at the left side. |
Return Value
It returns a copy of the string with trailing characters stripped.