用法:
bytes.zfill(width)
bytearray.zfill(width)
返回用 ASCII
b'0'
數字填充的序列的副本,以生成長度為width
的序列。前導符號前綴 (b'+'
/b'-'
) 通過在符號字符而不是之前插入填充after
來處理。對於bytes
對象,如果width
小於或等於len(seq)
,則返回原始序列。例如:
>>> b"42".zfill(5) b'00042' >>> b"-42".zfill(5) b'-0042'
注意
此方法的 bytearray 版本確實
not
就地操作 - 它總是產生一個新對象,即使沒有進行任何更改。
相關用法
- Python bytes.isupper用法及代碼示例
- Python bytes.isalpha用法及代碼示例
- Python bytes.hex用法及代碼示例
- Python bytes.title用法及代碼示例
- Python bytes.isalnum用法及代碼示例
- Python bytes.removesuffix用法及代碼示例
- Python bytes.split用法及代碼示例
- Python bytes.lstrip用法及代碼示例
- Python bytes.expandtabs用法及代碼示例
- Python bytes.splitlines用法及代碼示例
- Python bytes.rstrip用法及代碼示例
- Python bytes.isdigit用法及代碼示例
- Python bytes.istitle用法及代碼示例
- Python bytes.removeprefix用法及代碼示例
- Python bytes.strip用法及代碼示例
- Python bytes.islower用法及代碼示例
- Python bytes()用法及代碼示例
- Python bytearray()用法及代碼示例
- Python binascii.crc32用法及代碼示例
- Python base64.b64decode()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 bytes.zfill。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。