ljust
ljust is a string method in Python that returns a left-justified version of the string within a field of a specified width. The result is padded on the right with a fill character (by default a space). The method does not modify the original string but returns a new string.
Syntax and parameters: the method is called as s.ljust(width[, fillchar]). width is an integer that defines the
Return value: a new string that has length equal to width. If width exceeds the length of
- "cat".ljust(6) results in "cat ".
- "cat".ljust(6, '-') results in "cat---".
- "abcdefgh".ljust(5) remains "abcdefgh" because the width is not larger than the string length.
- "hi".ljust(3, '*') results in "hi*".
Related methods include rjust, center, and zfill, which align text to the right, center it, or pad