Python 3.9.0 has introduced two new methods to work with strings: removeprefix
and removesuffix
.
As their names suggest, one is used to remove a prefix from a string while the other one is used to remove a suffix.
removeprefix
Given a string and a prefix, if the string begins with the prefix, the prefix is being removed, otherwise a copy of the original string is being returned:
|
|
removesuffix
Given a string and a suffix, if the string ends with the suffix, the suffix is being removed, otherwise a copy of the original string is being returned:
|
|
Of course these are not the only features which have been added to Python 3.9.0, so I may cover more in the next days. If in the mean time you have any preferences, please leave a comment below and thanks for reading.