String Methods

str.ljust()

Pad the right side to left-align text. Width is a minimum code-point length, not a visual column width. No truncation occurs. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.ljust(width, fillchar=" ", /)

Parameters & Attributes

NameTypeDescription
widthintMinimum result length in Unicode code points; accepts index-compatible integers.
fillcharstrExactly one code point; defaults to ASCII space.

Return Value

str

Padded text, or unchanged text when width is no larger than its length.

Working Example

Example Snippetpython
print("pen".ljust(6, ".") + "2")print("book".ljust(6, ".") + "7")
Python Reference