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

Python ljust() method

Python ljust() method

Python Strings Python Strings


Description

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

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/python



str = "this is string example....wow!!!";



print str.ljust(50, '0');

The output of the above example is:



this is string example....wow!!!000000000000000000


Python Strings Python Strings