Home >>Python String Methods >Python String ljust() Method

Python String ljust() Method

Python String ljust() Method

Python String ljust() Method in python will returns the string left align and fill the remaining spaces with fillchars (default is a space).

Syntax:
string.ljust(length, character)

Parameter Values

Parameter Description
length It is required the returned string length
character It is Optional, character to fill the missing space in the string. Default is " " (space).
Here is an example of Python String ljust() Method:

just = "white"
x = just.ljust(25)
print(x, "is my favorite color.")

Output:
white                     is my favorite color.
Example 2:

str = 'Phptpoint'  
str = str.ljust(25,":")  
print(str)  

Output:
Phptpoint:::

No Sidebar ads