Python String ljust() Method Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Python ljust() method is used to left-justify a string, padding it with a specified character (space by default) to reach a desired width. This method is particularly useful when we want to align text in a consistent format, such as in tables or formatted outputs.Here's a basic example of how to use ljust() method: Python s1 = "Hello" s2 = s1.ljust(10) print(s2) OutputHello Explanation: In this example, the string "Hello" is left-justified to a width of 10 characters, with spaces added to the right.Table of ContentSyntax of ljust() Method :Using the default fill characterSpecifying a custom fill characterCombining ljust() with other string methods Syntax of ljust() methodstring.ljust(width, fillchar=' ')Parameters:width: The total width of the resulting string. If the original string is shorter than this width, it will be padded with the fillchar.fillchar (optional): The character to use for padding. The default is a space.Return Type: Returns a new string of given length after substituting a given character in right side of original string.Using the default fill characterThe ljust() method can be used without specifying a fillchar, in which case it defaults to a space. Python s = "Python" # Left-aligning the string with a total width of 12 res = s.ljust(12) print(res) OutputPython Explanation:The string s is left-aligned in a field of width 12.The remaining space is filled with spaces.Specifying a custom fill characterSometimes, we may want to use a character other than a space to fill the remaining space. The ljust() method allows you to specify a custom fillchar. Python s = "Data" # Left-aligning the string with # a width of 10 and using '-' as the fill character res = s.ljust(10, '-') print(res) OutputData------ Explanation:The fillchar parameter is set to '-', so the remaining space is filled with dashes.This can be useful for creating custom formatting styles.Combining ljust() with other string methods ljust() method can also be used alongside other string methods to achieve more complex formatting. Python s = "Align" # Left-aligning the string and converting it to uppercase res = s.ljust(10).upper() print(res) OutputALIGN Explanation:The string s is left-aligned in a field of width 10.The resulting string is then converted to uppercase using the .upper() method. Comment More info A AmiyaRanjanRout Follow Improve Article Tags : Python Python-Built-in-functions python-string Python-string-functions Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 7 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 6 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like