-1
>>> adf = "123 ABCD#"
>>> df = "<ABCD#>" 
>>> adf.strip(df)
>>> '123 '
>>> xc = "dfdfd ABCD#!"
>>> xc.strip(df)
>>> 'dfdfd ABCD#!'

Why does strip() take out ABCD# in adf? Does strip completely ignore "<" and ">" ?Why does it remove the chars when no "<" and ">" are there in the original string?

typing...
  • 934
  • 2
  • 10
  • 25
  • why does it matter? – typing... Oct 15 '16 at 01:06
  • Consider `'www.example.com'.strip('cmowz.<>')` The characters used to strip are a set; any characters on both ends of the string are removed until they cannot be removed. – dawg Oct 15 '16 at 01:21
  • Would it kill people to read [the docs](https://docs.python.org/3/library/stdtypes.html#str.strip) before asking questions that are so trivially answered? – ShadowRanger Oct 15 '16 at 02:02

1 Answers1

1

The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters).

The characters that are in df, they occur at the end in the string adf. This is not the case in string xc where the first and last character are ! and d.

str.strip([chars]); => If any character in str occurs in chars at last or first index, then that character is stripped off from str. Then it again checks. When no character is stripped, it stops.

Raza
  • 205
  • 1
  • 8