Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
rjust
communitycreator

How does rjust() work in Python?

Hassan Ahmed

The rjust() method in Python is used to return a right-justified version of the string that is calling the method.

Syntax

str.rjust(length, char)

Parameters

This method requires the length of the returned string to be passed as a parameter.

char is an optional parameter used to fill the remaining space of width in the string.

Code

Example 1

string = "This is a string."

print(string.rjust(30))
Example of rjust() method without second parameter

Example 2

string = "This is a string."

print(string.rjust(30, '0'))
Example of rjust() method without second parameter

RELATED TAGS

python
rjust
communitycreator
RELATED COURSES

View all Courses

Keep Exploring