Remove Arbitrary Leading Character From A Python String With .lstrip()
Passing a string of characters to [TODO: Code shorthand span ] will remove those characters from the start of the string being operated on. For example :
python
= f
=
Details
-
This example passes a string with four characters to ` .lstrip() ` : "a", "b", " " (space), and " \ n" (newline)
-
Any number of the given characters in any different combination are removed
-
As soon as a character that's not in the argument is seen, no further removal is done (hence the single "a" character in the example above remaining since it's behind the "x"
-
See also .removeprefix() for how to remove a specific string instead of a set of characters
Footnotes And References
- •
- •