Skip to content

Commit c992072

Browse files
authored
Merge pull request #6090 from DudeNr33/doc-bad-str-strip-call
Add examples for ``bad-str-strip-call``
2 parents 6505c74 + 102646e commit c992072

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
my_string = "Hello World"
2+
my_string.strip("Hello") # [bad-str-strip-call]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
A common misconception is that ``str.strip('Hello')`` removes the *substring* ``'Hello'`` from the beginning and end of the string.
2+
This is **not** the case.
3+
From the `documentation <https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip>`_:
4+
5+
> The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped
6+
7+
Duplicated characters in the ``str.strip`` call, besides not having any effect on the actual result, may indicate this misunderstanding.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
my_string = "Hello World"
2+
my_string.strip("Helo")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Documentation: `str.strip([chars]) <https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip>`_

0 commit comments

Comments
 (0)