numpy.char.zfill#

char.zfill(a, width)[source]#

傳回數字字串,左側以零填充。前導符號前綴(+/-)的處理方式是在符號字元之後而不是之前插入填充。

參數:
aarray-like,具有 StringDTypebytes_str_ dtype
widtharray-like,具有任何整數 dtype

字串寬度,用於在 a 中元素左側填充。

傳回值:
outndarray

StringDTypebytes_str_ dtype 的輸出陣列,取決於輸入類型

另請參閱

str.zfill

範例

>>> import numpy as np
>>> np.strings.zfill(['1', '-1', '+1'], 3)
array(['001', '-01', '+01'], dtype='<U3')