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)
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.pad.html
numpy.pad — NumPy v2.5 Manual
If a dict, each key is an axis and its corresponding value is an int or int pair describing the padding (before, after) or pad width for that axis.
🌐
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 - In Python, padding is primarily applied to strings, numbers, and data structures to ensure consistent presentation or to meet specific requirements in tasks like data processing, formatting output, or encryption.
🌐
Stack Abuse
stackabuse.com › padding-strings-in-python
Padding Strings in Python
September 18, 2023 - We love Python. Right Padding: Use < inside placeholders to left align a string:
🌐
Medium
medium.com › @johnidouglasmarangon › padding-f-strings-in-python-977b17edbd36
Padding f-strings in Python
February 18, 2022 - number = 2022 padding = 10print(f"{'decimal':<{padding}}{number:d}") print(f"{'octal':<{padding}}{number:o}") print(f"{'hex':<{padding}}{number:X}") print(f"{'binary':<{padding}}{number:b}")>>> decimal 2022 >>> octal 3746 >>> hex 7E6 >>> binary 11111100110
🌐
Python Engineer
python-engineer.com › posts › pad-zeros-string
How to pad zeros to a String in Python - Python Engineer
zfill is the best method to pad zeros from the left side as it can also handle a leading '+' or '-' sign.
Find elsewhere
🌐
Finxter
blog.finxter.com › home › learn python blog › python how to pad zeros to a string?
Python How to Pad Zeros to a String? - Be on the Right Side of Change
November 16, 2020 - But we’re programmers, we hate typing! Surely there must be a way to code this? To pad zeros to a string, use the str.zfill() method. It takes one argument: the final ... Read more
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pad-or-fill-a-string-by-a-variable-in-python-using-f-string
Pad or fill a string by a variable in Python using f-string - GeeksforGeeks
July 15, 2025 - We can pad strings to the left, right, or centre by using f-strings with a variable as the padding character.
🌐
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.
🌐
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))
🌐
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
🌐
CSEstack
csestack.org › home › python padding | how to pad zeros to number or string?
Python Padding | How to Pad Zeros to Number or String?
March 22, 2019 - Above code returns “7000” for “7000” even if you pass 3 as expected length after padding. In Python, you can not pad the integer number. You have to convert the number into the string.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python pad string with zeros
Python Pad String With Zeros - Spark By {Examples}
May 21, 2024 - How to pad string with zeros in Python? Adding some characters/values to the string is known as Padding. In Python, zfill() and rjust() methods are used
🌐
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, ...
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › pad
Python Numpy pad() - Padding Array Elements | Vultr Docs
November 18, 2024 - The numpy.pad() function in Python is a versatile tool used for padding arrays.