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 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.

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 *