You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/string-methods/about.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,17 +126,17 @@ Python `3.9` introduces two new string methods that make removing prefixes and s
126
126
>>>'TestHook'.removeprefix('Test')
127
127
'Hook'
128
128
>>>'bookkeeper'.removeprefix('book')
129
-
'bookkeeper'
129
+
'keeper'
130
130
```
131
131
132
132
[`<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.
133
133
134
134
```python
135
135
# removing a suffix
136
-
>>>'TestHook'.removesuffix('Test')
136
+
>>>'TestHook'.removesuffix('Hook')
137
137
'Test'
138
138
>>>'bookkeeper'.removesuffix('keeper')
139
-
'bookkeeper'
139
+
'book'
140
140
```
141
141
142
142
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
0 commit comments