...we've combined variables and text in print statements using commas and concatenation. eg
shape = 'rectangle'
num_sides = 4
print("A", shape, "has", num_sides, "sides.")
or
print("A "+shape+"has "+num_sides+"sides.")
When you print an integer 3 you get 3 on the screen as expected. If you change the variable to a float type you get 3.0 on the screen. The result of a normal divide (/) is always of a float data type so 12 / 4 = 3.0 Some decimals stop eg 5 / 8 = 0.625, others carry on for ever eg 1 / 3 = 0.333333333333333
If we want to display the shortened version of a long decimal on the screen, we usually don't want to change the value stored in that variable. We may need to multiply that variable by a big number and so rounding it off could cause inaccuracies if we have chopped it down to a couple of decimal places.
eg If you buy 1 million solar panels that are $8.24 each and you round that off to $8.20 you will be $40,000 short.
1,000,000 x 8.24 = 8,240,000
1,000,000 x 8.2 = 8,200,000
To control how many decimal places, or how many significant figures, we print we format the presentation of the data. This doesn't change the actual value of the data, just how it looks on the screen.
There are a couple of ways of doing this, the format function was intrduced in Python 3.0 (but was added to versions after 2.6), the f-string way of doing formatting was added in Python 3.6. If you are using an older version of Python (latest version is 3.13 as of March 2025) then f-strings may not work.