You are viewing a single comment's thread from:

RE: Learn Python Series (#3) - Handling Strings Part 2

in #utopian-io7 years ago

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

Sort:  

Thank you :)

Great and useful exercise. I haven't seem it yet, but I'm going to take time to read your posts soon :) I'm also a enthusiast pythonist, it's always a good idea keep reading and learning new tricks ;)

Honestly I have been inspired by you, I'm going to post tutorial's about great tools, techniques and ideas. I hope soon you could see by here my first tutorials on steemit =)

By the way, I didn't know that the for statement also contains a else clause, great men! Thank you for good content