Python rjust() method
Description
Python rjust() returns a new string with the original string right-aligned and padded with spaces to the length width. If the specified length is less than the string's length, the original string is returned.
Syntax
Syntax of the rjust() method:
str.rjust(width[, fillchar])
Parameters
- width -- specifies the total length of the string after padding with the specified character.
- fillchar -- the fill character, defaults to a space.
Return Value
Returns a new string with the original string right-aligned and padded with spaces to length width. If the specified length is less than the length of the string, the original string is returned
Example
The following example shows how to use the rjust() function:
#!/usr/bin/python
str = "this is string example....wow!!!";
print str.rjust(50, '0');
The output of the above example is:
000000000000000000this is string example....wow!!!
Python Strings