This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: for string methods strip, lstrip, rstrip, when param is a string which has more than one char, those methods is no useful currently
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, redrose2100, steven.daprano
Priority: normal Keywords:

Created on 2021-06-26 04:22 by redrose2100, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg396538 - (view) Author: redrose2100 (redrose2100) Date: 2021-06-26 04:22
for string methods strip, lstrip, rstrip, when param is a string which has more than 1 char, currently those methods remove char ,but not remove string , it is no useful

following is the results in python 3.9.5

Python 3.9.5 (default, May 18 2021, 14:42:02) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s="hellolloehb"
>>> print(s.lstrip("hello"))
b
>>> s="blloehhello"
>>> print(s.rstrip("hello"))
b
>>> s="helloehhollbllohhehello"
>>> print(s.strip("hello"))
b
>>>
In fact,
when s="hellolloehb" , s.lstrip("hello") expect to get "lloehb"
when s="blloehhello" , s.rstrip("hello") expect to get "blloeh"
when s="helloehhollbllohhehello" , s.strip("hello") expect to get "ehhollbllohhe"
msg396539 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-06-26 04:25
This is the intended behavior. Use s.removeprefix() and s.removesuffix() instead.
msg396540 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-06-26 04:28
Dennis is correct: these are working as attended, you have just misunderstood what they are supposed to do.
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88679
2021-06-26 04:28:26steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg396540

resolution: not a bug
stage: resolved
2021-06-26 04:25:38Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg396539
2021-06-26 04:22:23redrose2100create