Python String ljust() Method

Returns a left-justified version of the string with the specified width and fill character.

Syntax

Python
string.ljust(length, character = " ")

Parameters

ParameterDescription
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
print('My String'.ljust(20, '-'))

Output

My String-----------