Sometimes, we want to fill out a Python string with spaces.
In this article, we’ll look at how to fill out a Python string with spaces.
How to fill out a Python string with spaces?
To fill out a Python string with spaces, we can use the string ljust
method.
For instance, we write
s = 'hi'.ljust(10)
to call ljust
with 10 on 'hi'
to pad 'hi'
into length 10 with spaces.
Conclusion
To fill out a Python string with spaces, we can use the string ljust
method.