What is the print line doing?


#1

It says

print("%.2f" % total)

What is this doing?


#2

The expression is a string formatting template.

In the string,

"  __everything__in_quotes__
% formatting operator
.2 modifier
f value data type

Outside of the string

% operator
total variable/value

The data being printed is a float, represented by total. The modifier indicates two (2) decimal places, such as currency. The value is not altered, only copied and converted to a string.

Eg.

total =  15.695
print("%.2f" % total)    # 15.70