Python String ljust() Method
Returns a left-justified version of the string with the specified width and fill character.
Syntax
Python
Copy Code
string.ljust(length, character = " ")
Parameters
Parameter | Description |
---|---|
length |
Required. The length of the final string. If length is less than the length of the supplied. |
character |
Optional. The character to use for padding the string. Default is a space (" ") |
Example
Python
Copy Code
print('My String'.ljust(20, '-'))
Output
My String-----------