strip() method makes me confused
Because the strip methods argument is the set of characters to remove from either end. So it checks from the ends character by character until it finds a character that isn?t in the set. Then it removes everything prior to that (or after that at end of the string) and then returns the result.
So your first example leaves ?banana? as the string because all characters after and before that string in the original string were found in the set.
However in your second example the set only contains the comma and the string neither begins nor ends with commas so if (first character) in (set containing comma) returns false so it stops searching from that end and does the same at the other end.
Hope that helps.
Neilson Productions Limited
021 329 681
alexander at neilson.net.nz
> On 8/11/2020, at 00:06, Bischoop <Bischoop at vimart.net> wrote:
> According to documentation strip method removes heading and trailing
> Why then:
> txt = ",,,,,rrttggs...,..s,bananas...s.rrr"
> x = txt.strip(",s.grt")
> output: banana
> another example:
> text = "this is text, there should be not commas, but as you see there
> are still"
> y = txt.strip(",")
> this is text, there should be not commas, but as you see there are still