Centrare stringa in Python
Livello 242 battiture
Questo centra una stringa entro una larghezza specificata. Il metodo center() riempie con il carattere dato.
Codice Python
# Crea una stringa di 5 caratteri1text = "hello"# center(11, "*") riempie il testo con "*" fino a una larghezza totale di 11# 11 - 5 = 6 caratteri di riempimento, 3 per lato: stampa ***hello***2print(text.center(11, "*"))Output
***hello***
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(× 2)× 2,× 1.× 1*× 1=× 1