Formatting mini-language

In all cases, you can format injected values along the way by using Python's formatting mini-language. Just add a colon after your expression in the curly brackets, and then write the mini-language notation. Take this example:

>>> pct = .345
>>> value = 45500
>>> f‘Price grew by {pct:.1%} or ${value:,}'
'Price grew by 34.5% or 45,500'

More information on the Python formatting language can be accessed via the official documentation (https://docs.python.org/3/library/string.html#formatspec).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.85.183