ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
out = []
for i in range(3):
try:
if i == 1:
continue
out.append(i)
finally:
out.append('f')
print(out)- A. [0, 'f', 2, 'f']
- B. [0, 'f', 'f', 'f', 2]
- C. [0, 'f', 'f', 2, 'f']
- D. [0, 2, 'f', 'f']
Correct answer: C. [0, 'f', 'f', 2, 'f']
A finally block runs even when the try body executes continue, so the marker is added on every pass. The continue only skips the append of 1.
More Python Programming questions
- What is printed? python print(int('0x1f', 16), int('1f', 16), int('0o17', 8))
- What is printed? python print(divmod(-9, 4), -9 % 4, round(-9 / 4))
- What is printed? python print(len(str(float(1016))), str(1016 1.0), len(str(1016)))
- What is printed? python print(0.1 + 0.7 == 0.8, 0.8 - 0.7, 0.3 / 0.1, int(0.3 / 0.1))
- What is printed? python print(1.0 == 1, 1.5 // 0.5, 1.5 % 0.4, 2.0 -1074 > 0, 2.0 -1075 == 0)
- What is printed? python print(float.fromhex('0x1p-2'), 0.25 == float.fromhex('0x1p-2'), float.fromhex('0x1.8p1'))