Categories
Python Answers

How to fill out a Python string with spaces?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *