Correct format

Report a typo

Which of the following code snippets will correctly output formatted strings?

Consider the following when evaluating each option:

  1. The formatting should be applied successfully (the formatting operation is executed as intended, resulting in a formatted string).

  2. The code should not raise a SyntaxError.

Choose all correct options:

a)

"%.4f".format(3.14159265358979)

b)

"{1} {1} {1}".format(1, 2, 3)

c)

"{1} is a {kind}".format(kind="fruit", "grapefruit")

d)

"{city} is the capital of {country}".format(country="Portugal",
                                            city="Lisbon")

Pay attention to the syntax and the expected behavior of each formatting method. Consider how positional and keyword arguments are used in the .format() method, and how they correspond to the placeholders in the format string.

Select one or more options from the list
___

Create a free account to access the full topic