![]() |
VOOZH | about |
The rjust() method in Python is a string method used to right-align a string within a specified width by padding it with a specified character (default is a space). This method is helpful when you want to align text or numbers for formatting purposes.
geeks
Explanation:
Syntax: string.rjust(length, fillchar)
Parameters:
Return: Returns a new string of given length after substituting a given character in left side of original string.
In this example, original string "Python" has a length of 6 and width is specified as 12, so 6 '-' characters are added to the left to make the total length 12.
Output:
***geeksIn this example, specified width (3) is less than the length of the string (5), so the original string is returned without any padding.
World
In the below example, each number is right-aligned within a width of 5. The fillchar is specified as '0', so zeros are added to the left to fill the space.
00010 00200 00003