Menu Close

How to do string formatting in Python?

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.

Posted in Python, Python Answers