Categories
Python Answers

How to do string formatting in Python?

Spread the love

Sometimes, we want to do string formatting in Python

In this article, we’ll look at how to do string formatting in Python.

How to do string formatting in Python?

To do string formatting in Python, we can use the string format method.

For instance, we write

s = "[{0}, {1}, {2}]".format(1, 2, 3)

to call format with 3 values to interpolate them into the placeholders, which are the numbers surrounded with braces.

Conclusion

To do string formatting in Python, we can use the string format 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 *