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 ljust
method.
For instance, we write:
s = 'hi'.ljust(10)
print(s)
to call ljust
on 'hi'
to fill the string with spaces until its length is 10.
Therefore, s
is 'hi '
.
Conclusion
To fill out a Python string with spaces, we can use the ljust
method.