Latest web development tutorials

Python3 ljust () method

Python3 string Python3 string


description

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

grammar

ljust () method syntax:

str.ljust(width[, fillchar])

parameter

  • width - Specifies the length of the string.
  • fillchar - fill characters, the default is spaces.

return value

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

Examples

The following example shows ljust () to use:

#!/usr/bin/python3

str = "w3big example....wow!!!"

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

Examples of the above output results are as follows:

w3big example....wow!!!**************************

Python3 string Python3 string