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 the 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:
str.ljust(width[, fillchar])
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.
#!/usr/bin/python str = "this is string example....wow!!!"; print str.ljust(50, '0')
When we run the above program, it produces the 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.