The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Remove Arbitrary Leading Character From A Python String With .lstrip()

TODO: Pull subtitle into page object
Code
alfa = f"""  a  b  a

x a charlie"""

stripped = alfa.lstrip("ab \n")

print(f"START|{stripped}|END")
Results
START|x a charlie|END

Details

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Remove Arbitrary Leading Character From A Python String With .lstrip()

Passing a string of characters to `.lstrip()`` will remove those 
characters from the start of the string being operated on.
For example:


-- code
-- python

alfa = f"""  a  b  a

x a charlie"""

stripped = alfa.lstrip("ab \n")

print(f"START|{stripped}|END")

-- results/

START|x a charlie|END

-- /results

-- h3

Details

-- list 

- 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

-- ref
-- title: .lstrip() - Python Documentation
-- url: https://docs.python.org/3/library/stdtypes.html#str.lstrip

-- ref
-- title: .removeprefix() - Python Documentation
-- url: https://docs.python.org/3/library/stdtypes.html#str.removeprefix


-- categories
-- Python 

-- metadata
-- date: 2023-10-25 12:37:16
-- id: 2xgoejov
-- site: aws
-- type: post
-- status: published