# How can I fill out a Python string with spaces?

PythonServer Side ProgrammingProgramming

To pad the string on the right with spaces or any other character you can use the str.ljust(width[, fillchar]) method. The fillchar arg is used to specify the character to fill. For example:

## Example

To pad the string on the left with spaces or any other character you can use the str.ljust(width[, fillchar]) method. The fillchar arg is used to specify the character to fill. For example:

print('Mona Lisa'.ljust(12))
print('Mona Lisa'.ljust(12,'$')) ## Output Mona Lisa Mona Lisa$
Published on 11-Dec-2017 10:43:57