Python

Python Menu

Python

Python String ljust() - Definition, Syntax, Parameters, Examples

Definition

The ljust() method will left align the string, using a specified character (space is default) as the fill character.

Syntax

string.ljust(length, character)

Parameters

Parameter Description
length Required. The length of the returned string
character Optional. A character to fill the missing space (to the right of the string). Default is " " (space)

Examples:

testStr = "Python" result = testStr.ljust(20) print(result, "is my favorite programming language.") # another example, with padding ('*') testStr = "Python" result = testStr.ljust(20, "*") print(result)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods