+ 1

Why do I get the output like this?

>>>'text_files/cats.txt'.strip('text_files/') >>>cats. Why is the output so even though there is nothing like 'text_files/' on the right side of the given string

22nd Jun 2018, 12:06 AM
Anuj Kumar Nath
Anuj Kumar Nath - avatar
2 Answers
+ 3
strip() removes characters from the beginning and end. It looks for the characters and not the string itself. Characters "xt" in text word is the reason for that. You may want to change strip() to split() 'text_files/cats.txt'.split('text_files/')[1]
22nd Jun 2018, 12:41 AM
Toni Isotalo
Toni Isotalo - avatar
0
Toni Isotalo Thanks for your replyâ˜ș ,my confusion got cleared, it worked fine with .lstrip() method call on the string.
22nd Jun 2018, 5:12 AM
Anuj Kumar Nath
Anuj Kumar Nath - avatar