Bytes Methods
bytes.zfill()
Pad on the left with ASCII zero bytes until the requested width is reached. If the first byte is an ASCII plus or minus sign, insert zeros immediately after it. No numeric parsing or validation occurs. Widths below the current length preserve the data. Returns bytes.
Formal Syntax & Structure
python syntaxpython
data.zfill(width, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| width | int | Minimum length in bytes. |
Return Value
bytes
bytes padded with ASCII zeros, respecting an initial ASCII sign.
Working Example
Example Snippetpython
print(bytes(b'42').zfill(5))print(bytes(b'-42').zfill(5))print(bytes(b'+7').zfill(4))