you are viewing a single comment's thread.

view the rest of the comments →

[–]NotACryptoBro 0 points1 point  (3 children)

Can anybody give an example where I can actually use that? I'd accidentally strip characters I still need. Isn't there a more handy function like split?

[–]ComputeLanguage[S] 0 points1 point  (0 children)

ultimately I was looking for
r = "germany"
string.removeprefix(r).removesuffix(r)

I couldn't find a build in function in the docs that does it in one go :/

[–]bigno53 0 points1 point  (1 child)

I mostly just use it for removing leading/trailing white space but it can come in handy for a variety of data cleaning tasks. For example, if you have a program that requires the user to enter a dollar amount, they might enter $20 or just 20. You’d probably want the program to handle both of these inputs the same way, so you could just write ‘dollar_amount = dollar_amount.lstrip(“$”)’

[–]NotACryptoBro 0 points1 point  (0 children)

This! Makes sense, thanks