strip() method makes me confused

Bischoop Bischoop at vimart.net
Sat Nov 7 08:42:12 EST 2020


On 2020-11-07, Alexander Neilson <alexander at neilson.net.nz> wrote:
> 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. 
>
> https://www.programiz.com/python-programming/methods/string/strip
>
Yes, I got it know.

Thanks


More information about the Python-list mailing list