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

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

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$
Updated on 13-Feb-2020 10:04:40