Python String ljust() Method Last Updated : 02 Jan, 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 infoAdvertise with us Next Article Python String ljust() Method A AmiyaRanjanRout Follow Improve Article Tags : Python Python-Built-in-functions python-string Python-string-functions Practice Tags : python Similar Reads Python String lstrip() Method The lstrip() method removes leading whitespace characters from a string. We can also specify custom characters to remove from the beginning/starting of the string.Let's take an example to remove whitespace from the starting of a string.Pythons = " Hello Python!" res = s.lstrip() print(res)OutputHell 2 min read Python String isalnum() Method The isalnum() method is a string function in Python that checks if all characters in the given string are alphanumeric. If every character is either a letter or a number, isalnum() returns True. Otherwise, it returns False. For Example:Pythons = "Python123" res = s.isalnum() print(res)OutputTrue Exp 2 min read Python String Methods Python string methods is a collection of in-built Python functions that operates on strings.Note: Every string method in Python does not change the original string instead returns a new string with the changed attributes. Python string is a sequence of Unicode characters that is enclosed in quotatio 5 min read Python String center() Method center() method in Python is a simple and efficient way to center-align strings within a given width. By default, it uses spaces to fill the extra space but can also be customized to use any character we want. Example:Pythons1 = "hello" s2 = s1.center(20) print(s2)Output hello Explanation: Here, the 2 min read String lower() Method in Python lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method:Pythons = "HELLO, WORLD!" # Change all uppercase letters to lowercase res = s.lower() prin 3 min read Python String rjust() Method The rjust() method in Python is a string method used to right-align a string within a specified width by padding it with a specified character (default is a space). This method is helpful when you want to align text or numbers for formatting purposes.Pythons = 'geeks' res = s.rjust(10) print(res)Out 2 min read Python List methods Python list methods are built-in functions that allow us to perform various operations on lists, such as adding, removing, or modifying elements. In this article, weâll explore all Python list methods with a simple example.List MethodsLet's look at different list methods in Python:append(): Adds an 3 min read Python - Sympy Triangle.is_right() method In Sympy, the function Triangle.is_right() is used to check whether the given triangle is Right-Angled Triangle or not. Right-Angled Triangle is the triangle in which one angle is a right angle(90 degrees). Syntax: Triangle.is_right() Returns: True: if it is right-angled, otherwise False Example #1: 1 min read Python | Decimal is_snan() method Decimal#is_snan() : is_snan() is a Decimal class method which checks whether the Decimal value is a signaling NaN Syntax: Decimal.is_snan() Parameter: Decimal values Return: true - if the Decimal value is a signaling NaN; otherwise false Code #1 : Example for is_snan() method Python3 # Python Progra 2 min read Python | Decimal sqrt() method Decimal#sqrt() : sqrt() is a Decimal class method which returns the Square root of a non-negative number to context precision. Syntax: Decimal.sqrt() Parameter: Decimal values Return: the Square root of a non-negative number to context precision. Code #1 : Example for sqrt() method Python3 # Python 2 min read Like