The char.ljust()
function in Python is used to return an array with the length of an input array that is left-justified in a string of a given length.
char.ljust(a, width, fillchar=' ')
The char.ljust()
function takes the following parameter values:
a
: This represents the input array.width
: This represents the length of the output string.fillchar
: This represents the character that is used for padding.The char.ljust()
function returns an array of strings or Unicode. The value that is returned depends on the input type in the function.
import numpy as np# llmyarray = np.char.ljust('Theo', 10, fillchar = '*')print(myarray)
"Theo"
. Then, we choose to return an array of string with a length of 10
and for the remaining spaces after the "Theo"
to be filled with the character "*"
.