String Methods
lstrip()
Remove whitespace or chosen characters from the left end.
str.lstrip(chars=None)
str.lstrip() returns a copy of the string with leading characters removed.
If chars is omitted or None, all leading whitespace is stripped.
Parameters
| Name | Description |
|---|---|
| chars | Optional characters to remove from the left end; it is not a literal prefix. |
Returns
A new string with matching leading characters removed.
Try it
Run it and change it
text = " hello"
print("[" + text.lstrip() + "]")
Worth knowing
- Set of characters: The
charsargument is a set of individual characters to strip, not a literal prefix. To strip a literal prefix, useremoveprefix().