+ 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
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]
0
Toni Isotalo Thanks for your replyâșïž ,my confusion got cleared, it worked fine with .lstrip() method call on the string.