The ljust() method in Python returns the string which is left justified in a string of length width. Padding is done making use of the specified fillchar where the default is a space. The original string is returned when width is less than len(s). This function in Python String left aligns the string as per the width specified and fills the remaining space of line using blank space when fillchar argument isn’t passed.
Following is the syntax for ljust() method:
- width − This is the string length obtained in total after padding.
- fillchar − This is a filler character where default is a space.
This method in Python String returns the string left justified within a string of length width. Padding is done making use of the specified fillchar where default is a space. The original string is returned when the width is less than len(s).
The following example shows the usage of ljust() method.
str = "this is string example....wow!!!";
print str.ljust(50, '0')
When we run above program, it produces following result
this is string example....wow!!!000000000000000000
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.