stuff = {
    'apple': 1.97,
    'banana': 2.99,
    'cherry': 3.99,
}

# Common pattern of .format use: use numerical indexes

for name, price in stuff.items():
    print('The price of {0} is {1}.'.format(name, price))

"""
Explanation: f-strings
f-strings
are
new in Python 3.6.
f-strings look like an ordinary strings with an f in front.
They look like an ordinary (immutable) string that does not change,
but they are not immutable strings.
They are dynamic expressions!!!
One can put expressions within curly braces in an f-string,
and the expressions will be evaluated each time,
and then converted to a string.
The most common expressions used are just variable names.
It is a more
DRY
way of doing formatting than str.format.
Follow 80/20 rule.
So avoid covering complicated stuff and edge cases:
- format specifiers
- curly braces within the f-string
- nested f-strings

Let's look at how formatting is often done with the
str.format
method, then see how formatting is done with
f-strings.
End of explanation
"""


# Common pattern of .format use: use parameter names

for name, price in stuff.items():
    print(
        'The price of {name} is {price}.'.
        format(name=name, price=price))

"""
Explanation: In 'The price of {0} is {1}' above,
one must read back and forth to match
the numerical indexes in the string
with the .format method arguments.
Having to figure out what the numerical indexes are for hurts readability.
Which leads to a better way below
using named arguments to the .format method
so that meaning is obvious in the format string.
End of explanation
"""


for name, price in stuff.items():
    print(f'The price of {name} is {price}.')

"""
Explanation: Something that sucks about the above print,
is that name and price appear three times each.
I.e., It is not
DRY.
With f-strings, name and price only have to appear once,
making the code easier to read and maintain
as in the following example.
End of explanation
"""


tax_rate = 0.50

for name, price in stuff.items():
    print(f'The total price of {name} is {round(price * (1+tax_rate), 2)}.')

"""
Explanation: It reminds me of shell syntax. For example,
echo "The price of ${name} is ${price}"

It gets better. One may put expressions
within the curly braces in an f-string.
One is not limited to using just variable names.
End of explanation
"""


tax_rate = 0.50

for name, price in stuff.items():
    total_price = round(price * (1+tax_rate), 2)
    print(f'The total price of {name} is {total_price}.')

"""
Explanation: But what does round(price * (1+tax_rate), 2) mean? 
What is it for?
Just because you can put expressions in a f-string
does not mean that you should.
In the cell below, a temporary variable is used for documentation
to make the code easier to read.
End of explanation
"""


