Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
2. The format() function can display decimal values in hexadecimal or binary formats. True
or false?
3. What format() function formatting code should you use to display a monetary value that
requires two decimal places?

Answers


1. c. The replace() function allows us to search for a specific string value and replace it with
another string value within a larger string value.
2. True. You can specify whether to use decimal, hexadecimal, or binary formats when you
display variable values using the format() function.
3. .2f. The “f” tells Python to display the value as a floating point number, and the “.2” tells it to
display only two decimal places of the floating point value. This is exactly what you need for
displaying monetary values!
Free download pdf