Method Name
removesuffix
Method Signature
removesuffix(suffixToRemove)
Overview
- The method removes a given suffix from str object and returns the new string.
- If the given suffix is not found then it returns the original string.
Parameters
suffixToRemove - The suffix to be removed.
Return Value
A string containing the new value. If no suffix is found, original string is returned.
Example:
# Example Python program that removes a suffixfrom a string
qty = "10 yards";
qtyWithoutUnit = qty.removesuffix(" yards");
print("String after removing the suffix:");
print(qtyWithoutUnit);Output:
String after removing the suffix:
10