numpy.char.rjust#

char.rjust(a, width, fillchar=' ')[source]#

傳回一個陣列,其元素在長度為 width 的字串中靠右對齊。

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

結果字串的長度,除非 width < str_len(a)

fillchararray-like,具有 StringDTypebytes_str_ dtype

可選的填充字元(預設為空格)。

傳回:
outndarray

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

另請參閱

str.rjust

註解

雖然 afillchar 可能具有不同的 dtype,但不允許在 a 的 dtype 為「S」時,於 fillchar 中傳遞非 ASCII 字元,並且會引發 ValueError

範例

>>> import numpy as np
>>> a = np.array(['aAaAaA', '  aA  ', 'abBABba'])
>>> np.strings.rjust(a, width=3)
array(['aAaAaA', '  aA  ', 'abBABba'], dtype='<U7')
>>> np.strings.rjust(a, width=9)
array(['   aAaAaA', '     aA  ', '  abBABba'], dtype='<U9')