Python rjust() Method

Python 字符串Python String


Description

Python rjust() returns a new string with the original string right-aligned and padded with spaces to the length of width. If the specified length is less than the length of the string, the original string is returned.

Syntax

rjust() method syntax:

str.rjust(width[, fillchar])

Parameters

  • width -- Specifies the total length of the string after padding with the specified character.
  • fillchar -- The character to pad with, defaults to space.

Return Value

Returns a new string with the original string right-aligned and padded with spaces to the length of width. If the specified length is less than the length of the string, the original string is returned.

Example

The following example demonstrates 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 字符串Python String

Other Extensions