numpy.strings.zfill — NumPy v2.6.dev0 Manual

strings.zfill(a, width)

[source]

#

Return the numeric string left-filled with zeros. A leading sign prefix (+/-) is handled by inserting the padding after the sign character rather than before.

Parameters:aarray-like, with StringDType, bytes_, or str_ dtypewidtharray_like, with any integer dtypeWidth of string to left-fill elements in a.

Returns:outndarrayOutput array of StringDType, bytes_ or str_ dtype, depending on input type

Examples

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