Python Lessons – 5.7 String formatting

Python Lessons - 5.7 String formatting

String Formatting

So far we have seen some methods for combining strings with non-string values, converting them to strings. Actually there is a much more efficient way to add non-string values to strings.

A string is defined in the classic method, but inserting increasing integers enclosed in braces {}. Then the same string is referenced together with its format() method, in which each argument will replace the numbers between the brackets {i} staples in the string.

If you run it, you get

Reference values can be used instead of integers between the braces.

If you run it, you get:

⇐ Go to Python Lesson 5.6 – List comprehension

Go to Python Lesson 5.8 – Some useful functions for numbers and strings ⇒

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.