Skip to content

Commit

Permalink
Make it clear the prefix/suffix is removed at most once
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell authored and laurentlb committed Feb 15, 2022
1 parent a2d07b2 commit 7329175
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -3933,27 +3933,31 @@ If S does not contain `x`, `partition` returns `(S, "", "")`.
<a id='string·removeprefix'></a>
### string·removeprefix

`S.removeprefix(x)` removes the prefix `x` from the string S and returns the rest of the string.
`S.removeprefix(x)` removes the prefix `x` from the string S at most once,
and returns the rest of the string.
If the prefix string is not found then it returns the original string.

`removeprefix` fails if `x` is not a string.

```python
"banana".removeprefix("ban") # "ana"
"banana".removeprefix("ana") # "banana"
"bbaa".removeprefix("b") # "baa"
```

<a id='string·removesuffix'></a>
### string·removesuffix

`S.removesuffix(x)` removes the suffix `x` from the string S and returns the rest of the string.
`S.removesuffix(x)` removes the suffix `x` from the string S at most once,
and returns the rest of the string.
If the suffix string is not found then it returns the original string.

`removesuffix` fails if `x` is not a string.

```python
"banana".removesuffix("ana") # "ban"
"banana".removesuffix("ban") # "banana"
"bbaa".removesuffix("a") # "bba"
```

<a id='string·replace'></a>
Expand Down

0 comments on commit 7329175

Please sign in to comment.