<div>Hi Robin,<br></div><div><br></div><div>It's not a question about the documentation, so I think you posted to the wrong mailing list, maybe tutor would be a better choice.<br></div><div><br></div><div>I don't know where you see a bug, the documentation for strip [1] contains:<br></div><div><br></div><div>> The <i>chars</i> argument is a string specifying the set of characters to be removed.<br></div><div><br></div><div>in "ea".strip("ge") you're asking: "From the string 'ea', remove leading and trailing 'g's and 'e's", which results in "a", it looks correct to me.<br></div><div><br></div><div>The hard point to get may be the fact that strips takes a *set* of letters to strip, not a word to strip. If you want to strip words you can use re like this:<br></div><div><br></div><div>>>> re.sub("^hello|hello$", "", "hello world is hello")<br></div><div>' world is '<br></div><div><br></div><div>^hello meaning "hello at the beginning"<br></div><div>| means or<br></div><div>hello$ means "hello at the end"<br></div><div><br></div><div>So it reads like this: "hello at the beginning or hello at the end are replaced by the empty string". Note that the space are kept, we did *not* asked for them to be dropped (they can easily be drop by using strip agian.<br></div><div><br></div><div>Please not my "re" example is not perfect, it strips only once.<br></div><div><br></div><div>A more robust one could be:<br></div><div><br></div><div>>>> def wstrip(word, string):<br></div><div>...     return re.sub(f"^({re.escape(word)}\s?)*|(\s?{re.escape(word)})*$", "", string)<br></div><div>...<br></div><div>>>> wstrip("hello", "hello hello hello youpi hello hello")<br></div><div>'youpi'<br></div><div>>>> wstrip("hello", "hello hello hello hello hello")<br></div><div>''<br></div><div><br></div><div>But it's probably not foolproof, not well tested, and not that readable.<br></div><div><br></div><div>[1]: <a href="https://docs.python.org/3/library/stdtypes.html#str.strip">https://docs.python.org/3/library/stdtypes.html#str.strip</a><br></div><div><br></div><div class="protonmail_signature_block"><div class="protonmail_signature_block-user"><div>-- <br></div><div>Julien Palard<br></div><div>https://mdk.fr<br></div></div><div class="protonmail_signature_block-proton protonmail_signature_block-empty"><br></div></div><div><br></div><div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br></div><div> On Saturday 6 July 2019 14:08, chinapython@yeah.net <chinapython@yeah.net> wrote:<br></div><div> <br></div><blockquote class="protonmail_quote" type="cite"><div><span></span>hi.all<br></div><div><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)">    </span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">  </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt"> I'm robin.come from china,</span></span></span><span style="background-color:transparent">I </span><span style="background-color:transparent">have a question about "strip":</span><br></div><div><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)">    </span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">   version:</span></span></span><span style="background-color:transparent">Python 3.7.0</span><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)">    </span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent">>>> a='ea'</span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">>>> print([a.strip()])</span></span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">['ea']</span></span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">>>> print([a.strip('page')])</span></span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">['']</span></span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">>>> print([a.strip('ge')])</span></span></b><br></div><div><b><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><span style="font-size:10.5pt">    </span></span></span><span style="background-color:transparent"><span style="font-size:10.5pt">['a']</span></span></b><br></div><div><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><b><span style="font-size:10.5pt">    </span></b></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><b><span style="font-size:10.5pt">    </span></b></span></span><span style="background-color:rgba(0, 0, 0, 0)"><span style="color:rgb(0, 0, 0)"><b><span style="font-size:19px"> is this a bug?</span></b></span></span><br></div><div><br></div><div><span style="background-color:transparent"></span><br></div><div><br></div><div><hr style="width: 210px; height: 1px;" size="1" color="#b5c4df" align="left"><br></div><div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>chinapython@yeah.net<br></div></div></span></div></blockquote><div><br></div>