Metodo Python String zfill ()

Descrizione

Metodo delle stringhe Python zfill() stringa pad a sinistra con zeri per riempire la larghezza.

Sintassi

Di seguito è riportata la sintassi per zfill() metodo -

str.zfill(width)

Parametri

  • width- Questa è la larghezza finale della stringa. Questa è la larghezza che otterremmo dopo aver riempito gli zeri.

Valore di ritorno

Questo metodo restituisce una stringa imbottita.

Esempio

L'esempio seguente mostra l'utilizzo del metodo zfill ().

#!/usr/bin/python

str = "this is string example....wow!!!";
print str.zfill(40)
print str.zfill(50)

Quando eseguiamo il programma sopra, produce il seguente risultato:

00000000this is string example....wow!!!
000000000000000000this is string example....wow!!!