Python3 ljust() method
Description
The ljust() method returns a new string with the original string left-aligned and padded with spaces to the specified length. If the specified length is less than the length of the original string, the original string is returned.
Syntax
The syntax of the ljust() method is:
str.ljust(width[, fillchar])
Parameters
- width -- The specified string length.
- fillchar -- The fill character, default is a space.
Return value
Returns a new string with the original string left-aligned and padded with spaces to the specified length. If the specified length is less than the length of the original string, the original string is returned.
Example
The following example demonstrates the usage of the ljust() method:
#!/usr/bin/python3 str = "Example example....wow!!!" print (str.ljust(50, '*'))
The output of the above example is:
Example example....wow!!!**************************
Other extensions
Python3 String