14 String Formatting

There are a lot of different ways to format and display text in Python[3].

You can find a lot of excellent reference materials on W3 Schools.

Using { } inside a string[4] will allow the user to insert the contents form a variable[1] using the format() function[2].

The format function takes any number of arguments inside the ().

The first { } will take the first argument the second { } the second argument and so on.

You can also format the display :.2f means format to 2 decimal paces.

format_this = 2.7456
print("Default formatting {}".format(format_this))
print("Two decimal places {:.2f}".format(format_this))
Terms definitions
1. variable. A placeholder for a piece of information that can change.
2. function. A named section of a computer program that performs a specific task. Functions help make code more efficient and reusable. They may take input parameters and produce output.
3. Python. A type of programming language. It is one of many high-level, general-purpose programming languages. It was first released in 1991
4. string. A data type used to store text. Often enclosed in “” or ”