CKTIS / Python
str.rstrip
Removes trailing characters as long as each belongs to the supplied character set.
Version: Python 3.14; repository image, production runtime not attested
Syntax
s.rstrip(chars=None, /)Removes trailing characters as long as each belongs to the supplied character set.
Matching uses individual characters. Use exact suffix removal when the extension is a single indivisible unit.
Without chars, trailing whitespace is removed. In context.txt the set .tx strips the suffix and continues through the final t and x of context, leaving conte; exact .txt removal leaves context.
assert "box.txt".rstrip(".tx") == "bo" and "box.txt".removesuffix(".txt") == "box"
Examples
print("context.txt".rstrip(".tx"))
print("context.txt".removesuffix(".txt"))
Result
conte context
Without chars, trailing whitespace is removed. In context.txt the set .tx strips the suffix and continues through the final t and x of context, leaving conte; exact .txt removal leaves context.