Python ljust() method
Description
The Python 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
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/python
str = "this is string example....wow!!!";
print str.ljust(50, '0');
The output of the above example is:
this is string example....wow!!!000000000000000000
Python Strings