Python3 ljust() method

Python3 字符串Python3 String


Description

The ljust() method returns a new string with the original string left-aligned and padded with spaces to the specified length. If the specified length is less than the length of the original string, the original string is returned.

Syntax

The syntax of the ljust() method is:

str.ljust(width[, fillchar])

Parameters

  • width -- The specified string length.
  • fillchar -- The fill character, default is a space.

Return value

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

Example

The following example demonstrates the usage of the ljust() method:

#!/usr/bin/python3

str = "Example example....wow!!!"

print (str.ljust(50, '*'))

The output of the above example is:

Example example....wow!!!**************************

Python3 字符串Python3 String

Other extensions