You can do this with str.ljust(width[, fillchar]):

Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s).

>>> 'hi'.ljust(10)
'hi        '
Answer from Felix Kling on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ add-padding-to-a-string-in-python
Add padding to a string in Python - GeeksforGeeks
July 23, 2025 - We can manually add padding by calculating the required number of characters and concatenating them to the string. ... s = "Python" width = 10 # Add padding padded = " " * (width - len(s)) + s # Right-align print(padded)
๐ŸŒ
Medium
medium.com โ€บ @johnidouglasmarangon โ€บ padding-f-strings-in-python-977b17edbd36
Padding f-strings in Python
February 18, 2022 - number = 2022 padding = ... octal 3746 >>> hex 7E6 >>> binary 11111100110 ... This is a way to use a set of format strings that will be interpreted together....
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ padding-strings-in-python
Padding Strings in Python
September 18, 2023 - Right padding is analogous to left padding - the given character is added to the end of the string until the string reaches a certain length. Python offers many functions to format and handle strings, their use depends on the use case and the developer's personal preference.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-pad-python-strings-with-custom-characters-419450
How to pad Python strings with custom characters | LabEx
String padding is a technique used to modify the length of a string by adding characters to its beginning or end. This process helps create uniform string lengths, which is crucial in various programming scenarios such as formatting output, ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Pad Strings and Numbers with Zeros in Python (Zero-padding) | note.nkmk.me
May 18, 2023 - This article explains how to perform zero-padding on various data types such as strings (str) and integers (int) in Python. Right-justified and zero-filled: zfill() Right-justified, centered, left-jus ...
๐ŸŒ
Kodeclik
kodeclik.com โ€บ python-pad-string
How to add padding to a Python string
October 16, 2024 - There are three ways to pad a Python string. 1. Left justify it so the padding is on the right. 2. Right justify it so the padding is on the left. 3. Center justify it so the padding is on both the left and right.
๐ŸŒ
Medium
medium.com โ€บ pythons-gurus โ€บ how-padding-works-in-python-and-how-to-use-it-8c0020830f8d
How Padding Works in Python and How to Use It | Pythonโ€™s Gurus
December 5, 2024 - Padding refers to the process of adding extra characters (usually spaces, zeros, or other symbols) to data, such as strings or numbers, to make them conform to a certain length or structure.
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Allow f-string to dynamically pad spaces - Python Help - Discussions on Python.org
June 27, 2023 - Example: # This works >>> print(f"{3:4}") '3 ' # However this does not work. >>> pad_amount: int = ... >>> print(f"3:pad_amount") ValueError: Unknown format code 'a' for object of type 'int' # I know this is the intended behavior, however the only other way to do this (or if you have better ways to do this please let me know) is using eval()
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-pad-a-string-to-a-fixed-length-with-spaces-in-python
How to Pad a String to a Fixed Length with Spaces in Python - GeeksforGeeks
July 23, 2025 - The center() method in Python pads a string to the specified length by adding spaces (or any other character) to both sides of the string.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ pad string with spaces in python
Pad String with Spaces in Python - Spark By {Examples}
May 21, 2024 - How to pad the string with spaces in Python? Adding some characters to the string is known as Padding or filling and is useful when you wanted to make a
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ padding-python
Python - String Padding Examples: ljust, rjust - Dot Net Perls
To pad strings in Python, we can use the format built-in or directly use ljust and rjust.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python pad string with spaces
How to Pad String With Spaces in Python | Delft Stack
February 2, 2024 - In this code, we use Pythonโ€™s string formatting method. We create a format string "{:15}" where the : indicates a placeholder for the string, and 15 specifies the desired width. We apply the format method to insert "I am legend" into this placeholder. When executed, the code pads the string with spaces on the right side, ensuring the output is 15 characters wide.
๐ŸŒ
CoenRaets
jsonviewer.ai โ€บ python-f-string-padding
Python f String Padding[Complete Guide with Examples] - JSON Viewer
July 5, 2023 - The character โ€œ>โ€ indicates right padding for the employee with a total width of 10, while the โ€œ<โ€ character indicates left padding for the id with the total width of 10. ... Here, the variable value is written after the string โ€œValue: โ€ The alignment of the value within a field of 10 characters is specified using the > character.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-pad-string
Python Pad String: A Comprehensive Guide - CodeRivers
February 22, 2026 - In Python, string padding is a useful operation that allows you to format strings in a specific way. Padding can be used to align text, create fixed-width fields, or add decorative elements to strings. This blog post will explore the fundamental concepts of Python pad string, different usage ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-padding-a-string-upto-fixed-length
Python | Padding a string upto fixed length - GeeksforGeeks
March 23, 2023 - # Python code to demonstrate # pad spaces in string # upto fixed length # initialising string ini_string = "123abcjw" padding_size = 15 # printing string and its length print ("initial string : ", ini_string, len(ini_string)) # code to pad spaces in string res = ini_string + " "*(padding_size - len(ini_string)) # printing string and its length print ("final string : ", res, len(res))