0

string = "xoxo love xoxo"

print(string.strip("xoe")) # -> Without space befor x Output will be love

print(string.strip(" xoe")) # -> With space before x Output will be lov

Why when i put a space before the letter (x) in the example it removes the letter (e) from the word (love) and when i do not put the space it does not remove anything ? [1]: https://i.stack.imgur.com/ZHeUX.png

Apex
  • 19
  • 3

1 Answers1

1

Consider what strip() does:

strip("xoe") looks from left and right and starts stripping an 'x' or 'o' or 'e'. When it encounters the space, it stops stripping so the 'e' will not be stripped.

strip(" xoe") does the same, but when it encounters the space, it strips the space and after that it strips the 'e' also.

Ronald
  • 2,930
  • 2
  • 7
  • 18