CKTIS / Python
str.zfill
Rellena con ceros ASCII hasta el ancho mínimo width.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
s.zfill(width)Rellena con ceros ASCII hasta el ancho mínimo width.
Un signo ASCII + o - inicial precede al relleno: -42 con ancho 5 queda -0042.
El ancho 2 no acorta el texto 123, que ya tiene tres caracteres.
assert "-7".zfill(4) == "-007" and "−7".zfill(4) == "00−7"
Ejemplos
print("-42".zfill(5))
print("123".zfill(2))
Resultado
-0042 123
El ancho 2 no acorta el texto 123, que ya tiene tres caracteres.