lawlermd (1) [Avatar] Offline
#1
Hello,

Your example is section 6.4.3:

x = "www.python.org"
x.strip(".gorw")
'python'

Why doesn't python strip out the "o" in "python"?

Your result is the same one I get in Python, but it does not make sense.
What am I missing?

Thanks,

Message was edited by:
lawlermd
naomi.ceder (134) [Avatar] Offline
#2
Re: Question about *.strip
The 'o' in "python" is safe because strip() will only remove characters from the ends of strings. So specifiying ".gorw" as the characters to strip is enough to remove both the "www." and the ".org", but that that leaves "python" which doesn't begin or end with any of ".gorw", so the stripping ends. If the characters to strip had been ".gnorw", then the result would have been "pyth", but there is no way that strip will remove characters from within a string.

I hope that makes sense?

And thanks for raising the question!