How to Use String ljust() Method in PythonPython Basics


The string ljust() method returns a left-justified string of given minimum width.

Example

#!/usr/bin/python3

str = "Python is the most famous language.!!!"

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

Output:

Python is the most famous language.!!!************

Syntax

string.ljust(width[, fillchar])

Parameters

Name Description
width Specifies the length of the string
Fillchar Padding character, defaults to a space

Return Value

It returns the left-justified string within the given minimum width.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us