ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(len('%d' % -0), '%d' % -0.0, '%.1f' % -0.0)- A. 1 1 -0.0
- B. 2 0 -0.0
- C. 1 0 0.5
- D. 1 0 -0.0
Correct answer: D. 1 0 -0.0
The integer -0 is just 0, so %d prints a single character. %d truncates -0.0 to the int 0, but %.1f keeps the sign bit of the float and prints -0.0.
More Python Programming questions
- What is printed? python print(max('abc', 'abd', key=lambda s: s[::-1]), min('ba', 'ab', key=len))
- What is printed? python print(sorted([1, 10, 2], key=lambda x: str(x)[0]))
- What is printed? python print(0.1 + 0.1 == 0.2, 0.1 + 0.1 + 0.1 == 0.3, 0.2 + 0.2 == 0.4)
- What is printed? python print(list(range(2, 20, 5)), list(range(-1, -10, -4)))
- What is printed? python print(len(str(71000)), 71000 % 10)
- What is printed? python print(10 -3 1000 == 1, 10 -3 1000)