ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print([y for x in range(5) if (y := x * x) > 5])
- A. [0, 1, 4, 9, 16]
- B. [16]
- C. [9, 16]
- D. [4, 9, 16]
Correct answer: C. [9, 16]
The walrus operator assigns y to x*x in the condition. Only squares greater than 5, which are 9 and 16, are kept by the comprehension.
More Python Programming questions
- What is printed? python print(bin(10).count('1'), (10).bitcount(), (-10).bitcount())
- What is printed? python from collections import Counter print(Counter('abracadabra').mostcommon(3))
- What is printed? python print(float(10 16 + 1) == 10 16, 10 16 + 1 == float(10 16 + 1))
- What is printed? python x = 0 def f(): global x x += 1 return x print(f() + f() 10, x)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 0.1 == 0.3 - 0.2 + 0.1)
- What is printed? python nums = [3, 1, 2] nums2 = sorted(nums, reverse=True) nums.sort() print(nums, nums2, nums is sorted(nums))