ProgrammingEasyTCS NQT · Wipro pattern
What is printed?
What is printed?
print([x * x for x in range(5) if x % 2])
- A. [0, 4, 16]
- B. [1, 9]
- C. [0, 1, 9]
- D. [1, 4, 9, 16]
Correct answer: B. [1, 9]
x % 2 is truthy only for odd x, so the filter keeps 1 and 3 from range(5). Their squares are 1 and 9.
More Python Programming questions
- What is printed? python s = "hello" print(s[::-2])
- What is printed? python t = (1,) print(type(t).name, type((1)).name)
- What is printed? python def f(args, kw): print(len(args), len(kw)) f(1, 2, a=3)
- What is printed? python print(list(zip([1, 2, 3], "ab")))
- What is printed? python print(" ".join(sorted(set("banana"))))
- What is printed? python try: print(1 / 0, end=" ") except ZeroDivisionError: print("Z", end=" ") finally: print("F")