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

Python3 ljust() Method

Python3 ljust() Method

Python3 Strings Python3 Strings


Description

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

Syntax

Syntax of the ljust() method:


str.ljust(width[, fillchar])

Parameters

Return Value

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

Example

The following example shows how to use ljust():


#!/usr/bin/python3

str = "Runoob example....wow!!!"

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

The output of the above example is:


Runoob example....wow!!!**************************

Python3 Strings Python3 Strings