Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python rjust() method

Python rjust() method

Python Strings Python Strings


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

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 Python Strings