ProgrammingHardIBM · Deloitte · Product Company SDE
What does the following Python 3 code print? print("%d-%s-%.2f" % (5, "hi", 3.14159))
- A. %d-hi-3.14
- B. 5-hi-3.141
- C. 5-hi-3.1
- D. 5-hi-3.14
Correct answer: D. 5-hi-3.14
Old-style % formatting substitutes each specifier in order: %d->5, %s->hi, %.2f rounds 3.14159 to 3.14.
More Python Programming questions
- What does the following Python 3 code print? print(list(filter(lambda x: x % 2 == 0, range(10))))
- What is printed? python print(type(10 / 5))
- Which of these built-in Python types is immutable?
- What is printed? python s = "placement" print(s[2:5])
- What is printed? python print(len({1, 2, 2, 3, 3, 3}))
- Which keyword turns an ordinary Python function into a generator function?