Skip to content

Commit d6a52c5

Browse files
authored
#185, add removeprefix/removesuffix to the spec (#193)
* #185, add removeprefix/removesuffix to the spec * Make it clear the prefix/suffix is removed at most once
1 parent 200a5a9 commit d6a52c5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ interact with the environment.
164164
* [string·lower](#string·lower)
165165
* [string·lstrip](#string·lstrip)
166166
* [string·partition](#string·partition)
167+
* [string·removeprefix](#string·removeprefix)
168+
* [string·removesuffix](#string·removesuffix)
167169
* [string·replace](#string·replace)
168170
* [string·rfind](#string·rfind)
169171
* [string·rindex](#string·rindex)
@@ -777,6 +779,8 @@ Strings have several built-in methods:
777779
* [`lower`](#string·lower)
778780
* [`lstrip`](#string·lstrip)
779781
* [`partition`](#string·partition)
782+
* [`removeprefix`](#string·removeprefix)
783+
* [`removesuffix`](#string·removesuffix)
780784
* [`replace`](#string·replace)
781785
* [`rfind`](#string·rfind)
782786
* [`rindex`](#string·rindex)
@@ -3926,6 +3930,36 @@ If S does not contain `x`, `partition` returns `(S, "", "")`.
39263930
"one/two/three".partition("/") # ("one", "/", "two/three")
39273931
```
39283932

3933+
<a id='string·removeprefix'></a>
3934+
### string·removeprefix
3935+
3936+
`S.removeprefix(x)` removes the prefix `x` from the string S at most once,
3937+
and returns the rest of the string.
3938+
If the prefix string is not found then it returns the original string.
3939+
3940+
`removeprefix` fails if `x` is not a string.
3941+
3942+
```python
3943+
"banana".removeprefix("ban") # "ana"
3944+
"banana".removeprefix("ana") # "banana"
3945+
"bbaa".removeprefix("b") # "baa"
3946+
```
3947+
3948+
<a id='string·removesuffix'></a>
3949+
### string·removesuffix
3950+
3951+
`S.removesuffix(x)` removes the suffix `x` from the string S at most once,
3952+
and returns the rest of the string.
3953+
If the suffix string is not found then it returns the original string.
3954+
3955+
`removesuffix` fails if `x` is not a string.
3956+
3957+
```python
3958+
"banana".removesuffix("ana") # "ban"
3959+
"banana".removesuffix("ban") # "banana"
3960+
"bbaa".removesuffix("a") # "bba"
3961+
```
3962+
39293963
<a id='string·replace'></a>
39303964
### string·replace
39313965

0 commit comments

Comments
 (0)