Python3 ljust() Method
Description
The ljust() method returns a new string with the original string left-aligned and padded with spaces to a specified length. If the specified length is less than the length of the original string, the original string is returned.
Syntax
Syntax of the ljust() method:
str.ljust(width[, fillchar])
Parameters
- width -- specifies the length of the string.
- fillchar -- the fill character, defaults to a space.
Return Value
Returns a new string with the original string left-aligned and padded with spaces to a specified length. If the specified length is less than the length of the original string, the original string is returned.
Example
The following example shows how to use ljust():
#!/usr/bin/python3
str = "Runoob example....wow!!!"
print (str.ljust(50, '*'))
The output of the above example is:
Runoob example....wow!!!**************************
Python3 Strings