Hi, thx for your lengthy response, and welcome to Steemit by the way!
Besides strip()
, I do know about lstrip()
and rstrip()
. ;-)
I don't see too many use-cases for strip()
and its left/right brother and sister. Because when working with lots of (unstructured) textual data, you don't know upfront what can or cannot be stripped without inspecting the data, either manually or with a bunch of algos, and for the latter other methods are far more convenient / precise.
Ref. (as written above):
url = 'https://steemit.com'
domain = url.strip('htps:/')
print(domain)
# eemit.com
When trying to use strip()
for parsing URL strings for example, in order to remove the protocol / scheme from the URL, strip()
fails when the domain begins with either an 'h', 't', 'p', or 's'.
By the way, have you seen Learn Python Series (#4) - Round-Up #1? In there I've explained how to develop a parse_url()
function using only what's been covered in the first three episodes! Without using strip()
! :-)
(Also in there, using a for else
clause ! :P )
@scipio
RE: Learn Python Series (#3) - Handling Strings Part 2