ReferenceString methods
str.zfill()
Pads with leading zeros to the given width.
Signature
text.zfill(width)Parameters
| Name | Means |
|---|---|
width | the total length wanted |
Returns
A new string, unchanged if it is already long enough.
Example
Python
print("7".zfill(3))
print("1234".zfill(3))
print("-7".zfill(4))Output
007 1234 -007