rjust
rjust is a string method used in several programming languages to right-justify text within a specified field width by padding on the left. It is commonly used for formatting output in consoles, reports, or tables, where consistent column alignment is desirable. The core idea is to produce a string whose length equals the target width, adding a fill character or string to the left if the original string is shorter than the width. If the input string is already as long as or longer than the target width, the original string is returned.
In Python, the method is str.rjust(width, fillchar=' '). The fillchar, if provided, must be a single character;
In Ruby, the method is String#rjust(width, padstr=' '). The padstr can be more than one character, and
In JavaScript, the equivalent is String.prototype.padStart(targetLength, padString). If padString is omitted, a single space is used.
Related methods include ljust and center, which left-justify or center-align text, respectively. rjust remains a common