![]() |
VOOZH | about |
Python ljust() method is used to left-justify a string, padding it with a specified character (space by default) to reach a desired width. This method is particularly useful when we want to align text in a consistent format, such as in tables or formatted outputs.
Here's a basic example of how to use ljust() method:
Hello
Explanation:
Table of Content
string.ljust(width, fillchar=' ')
The ljust() method can be used without specifying a fillchar, in which case it defaults to a space.
Python
s is left-aligned in a field of width 12.Sometimes, we may want to use a character other than a space to fill the remaining space. The ljust() method allows you to specify a custom fillchar.
Data------
fillchar parameter is set to '-', so the remaining space is filled with dashes.ljust() with other string methodsljust() method can also be used alongside other string methods to achieve more complex formatting.
ALIGN
s is left-aligned in a field of width 10..upper() method.