CKTIS / Python
str.rstrip
Verwijdert rechts witruimte of tekens uit de optionele verzameling chars.
Versie: Python 3.14; repository image, production runtime not attested
Syntax
s.rstrip(chars=None, /)Verwijdert rechts witruimte of tekens uit de optionele verzameling chars.
In context.txt wist .tx de extensie en daarna t en x van de naam, zodat conte resteert.
Het exacte achtervoegsel .txt verwijderen laat context over.
assert "box.txt".rstrip(".tx") == "bo" and "box.txt".removesuffix(".txt") == "box"
Voorbeelden
print("context.txt".rstrip(".tx"))
print("context.txt".removesuffix(".txt"))
Resultaat
conte context
Het exacte achtervoegsel .txt verwijderen laat context over.