Fine stringa in Python
Livello 256 battiture
Questo verifica se la stringa termina con '.pdf'. Il metodo endswith() restituisce True se la stringa termina con il suffisso specificato.
Codice Python
# Crea una stringa che rappresenta un nome file1filename = "report.pdf"# endswith() verifica se la stringa termina con il suffisso dato# Restituisce True perché "report.pdf" termina con ".pdf"2print(filename.endswith(".pdf"))Output
True
Esercitati a digitare questo codice. I risultati non vengono registrati in classifica.
Simboli in questo codice
I simboli che digiti in questo codice Python e quante volte compaiono.
"× 4.× 3(× 2)× 2=× 1