Skip to content

Commit 36e596b

Browse files
BethanyGkotp
authored andcommitted
Quick Update to removeprefix/suffix code examples
1 parent dda7e08 commit 36e596b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

concepts/string-methods/about.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ Python `3.9` introduces two new string methods that make removing prefixes and s
126126
>>> 'TestHook'.removeprefix('Test')
127127
'Hook'
128128
>>> 'bookkeeper'.removeprefix('book')
129-
'bookkeeper'
129+
'keeper'
130130
```
131131

132132
[`<str>.removesuffix(<substring>)`][removesuffix] returns the string without the suffix (`string[:-len(substring)]`). If the `<substring>` isn't present, a copy of the original string will be returned.
133133

134134
```python
135135
# removing a suffix
136-
>>> 'TestHook'.removesuffix('Test')
136+
>>> 'TestHook'.removesuffix('Hook')
137137
'Test'
138138
>>> 'bookkeeper'.removesuffix('keeper')
139-
'bookkeeper'
139+
'book'
140140
```
141141

142142
For more examples and methods the [informal tutorial][informal tutorial] is a nice jumping-off point.
@@ -152,14 +152,12 @@ Python also supports regular expressions via the `re` module, which will be cove
152152
[howto unicode]: https://docs.python.org/3/howto/unicode.html
153153
[informal tutorial]: https://docs.python.org/3/tutorial/introduction.html#strings
154154
[locale]: https://docs.python.org/3/library/locale.html#module-locale
155+
[removeprefix]: https://docs.python.org/3.9/library/stdtypes.html#str.removeprefix
156+
[removesuffix]: https://docs.python.org/3.9/library/stdtypes.html#str.removesuffix
155157
[str-endswith]: https://docs.python.org/3/library/stdtypes.html#str.endswith
156158
[str-methods]: https://docs.python.org/3/library/stdtypes.html#string-methods
157159
[str-replace]: https://docs.python.org/3/library/stdtypes.html#str.replace
158160
[str-strip]: https://docs.python.org/3/library/stdtypes.html#str.strip
159161
[str-title]: https://docs.python.org/3/library/stdtypes.html#str.title
160162
[text sequence]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
161163
[unicode code points]: https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme
162-
163-
[removeprefix]: https://docs.python.org/3.9/library/stdtypes.html#str.removeprefix
164-
[removesuffix]: https://docs.python.org/3.9/library/stdtypes.html#str.removesuffix
165-

0 commit comments

Comments
 (0)