Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / Python

str.removesuffix

Remove uma única vez o sufixo exato.

Versão: Python 3.14; repository image, production runtime not attested

Sintaxe

s.removesuffix(suffix)

Remove uma única vez o sufixo exato.

Com .tar, a.tar.tar passa a a.tar, enquanto um sufixo vazio mantém todo o texto.

Uma fatia até −0 termina antes da posição zero e ficaria vazia.

assert "abc".removesuffix("") == "abc" and "abc"[:-0] == ""

Exemplos

print("a.tar.tar".removesuffix(".tar"))
print("a.tar".removesuffix(""))

Resultado

a.tar
a.tar

Uma fatia até −0 termina antes da posição zero e ficaria vazia.

Fontes