all Python 3Strings (str)function
str.ljust
alignment
Left-justify the string in a field of the given width, padded on the right.
Syntax
s.ljust(width[, fillchar])
ljust pads and never truncates: a string longer than width spills past the column in full, so a hard width needs a slice s[:width] as well. The width is counted in characters, not in the space a glyph occupies — emoji and CJK characters take two terminal cells, and the table drifts anyway. Inside a formatted string the same padding usually reads better as f'{s:<10}'.
Examples
print('hi'.ljust(5, '.')) # → hi...
print('hi'.ljust(5) + '|') # → hi |
print('hello'.ljust(3)) # → hello
See also
Open in the full glossarydocs.python.orgReport an inaccuracy