Python String - ljust(), rjust(), center() Last Updated : 02 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Strings are sequences of characters that we can manipulate in many ways. Sometimes we need to align a string to the left, right, or centre within a given space. In this article, we will explore the Difference between ljust(), just() and center().Table of Contentstr.ljust()Syntax of ljust()Example of ljust()str.rjust()Syntax of rjust()Example of rjust()str.center()Syntax of ljust()Example of center()str.ljust()ljust() method is used to align a string to the left side and fill the remaining space on the right with a specific character (or space by default).Syntax of ljust()string.ljust(width, fillchar)Parameterswidth: The total length of the string after padding.fillchar: The character to pad the string with (optional, default is space).Return Type:The return type of ljust() is a new string that is left-justified with padding.Example of ljust() Python s = "Burger" # Padding the name with dashes until length is 20 formatted_item = s.ljust(20, "-") print(formatted_item) OutputBurger-------------- str.rjust()The rjust() method aligns the string to the right side and fills the remaining space on the left with a specific character (or space by default).Syntax of rjust()string.rjust(width, fillchar)Parameterswidth: The total length of the string after padding.fillchar: The character to pad the string with (optional, default is space).Return Type:The return type of rjust() is a new string that is right-justified with padding.Example of rjust() Python a = "Hello" # Adding dashes to the left until length is 10 b = a.rjust(10, "-") print(b) Output-----Hello str.center()The center() method centers the string in the middle and fills both sides with a specific character (or space by default) to achieve a given width.Syntax of ljust()string.center(width, fillchar)Parameterswidth: The total length of the string after padding.fillchar: The character to pad the string with (optional, default is space).Return Type:The return type of center() is a new string that is centered with padding on both sides.Example of center() Python a = "Hello" # Adding dashes to both sides until length is 10 b = a.center(10, "-") print(b) Output--Hello--- Comment More infoAdvertise with us Next Article Python String - ljust(), rjust(), center() S Shambhavi Singh 1 Follow Improve Article Tags : Technical Scripter Python Python-Built-in-functions python-string Practice Tags : python Similar Reads String rjust() and ljust() in python() 1. String rjust() The string rjust() method returns a new string of given length after substituting a given character in left side of original string. Syntax: string.rjust(length, fillchar) Parameters: length: length of the modified string. If length is less than or equal to the length of the origin 2 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 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 Python | Pandas Series.str.center() Series.str can be used to access the values of the series as strings and apply several methods to it. Pandas Series.str.center() function is used for filling left and right side of strings in the Series/Index with an additional character. The function is equivalent to Python's str.center(). Syntax: 3 min read Python | Pandas Series.str.ljust() and rjust() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas .ljust() and .rjust() are Text methods used to deal with text data in series. S 3 min read Like