Skip to content

Commit

Permalink
Add removeprefix/removesuffix to string
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Feb 15, 2022
1 parent 689f544 commit 1ee0bca
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ interact with the environment.
* [string·lower](#string·lower)
* [string·lstrip](#string·lstrip)
* [string·partition](#string·partition)
* [string·removeprefix](#string·removeprefix)
* [string·removesuffix](#string·removesuffix)
* [string·replace](#string·replace)
* [string·rfind](#string·rfind)
* [string·rindex](#string·rindex)
Expand Down Expand Up @@ -3926,6 +3928,30 @@ If S does not contain `x`, `partition` returns `(S, "", "")`.
"one/two/three".partition("/") # ("one", "/", "two/three")
```

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

`S.removeprefix(prefix)` returns a copy of string S with the prefix `prefix`
removed if S starts with `prefix`, otherwise it returns S.

```python
"banana".removeprefix("ban") # "ana"
"banana".removeprefix("foo") # "banana"
"foofoobar".removeprefix("foobar") # "foo"
```

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

`S.removesuffix(suffix)` returns a copy of string S with the suffix `suffix`
removed if S ends with `suffix`, otherwise it returns S.

```python
"banana".removesuffix("nana") # "ba"
"banana".removesuffix("foo") # "banana"
"banana".removesuffix("na") # "bana"
```

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

Expand Down

0 comments on commit 1ee0bca

Please sign in to comment.