String Methods

str.zfill()

Pad with ASCII zeroes on the left until the requested minimum code-point width. If the initial character is an ASCII plus or minus sign, insert zeroes after it. The rest of the text need not be numeric. No truncation or number parsing occurs. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.zfill(width, /)

Parameters & Attributes

NameTypeDescription
widthintMinimum output length; accepts index-compatible integers.

Return Value

str

Zero-padded text.

Working Example

Example Snippetpython
print("42".zfill(5))print("-42".zfill(5))print("+۷".zfill(4))
Python Reference