ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print([x for x in range(5) if x % 2], [x for x in 'a1b2' if x.isdigit()], {x % 3 for x in range(6)})- A. [1, 3] ['1', '2'] {0, 1, 2}
- B. [0, 2, 4] ['1', '2'] {0, 1, 2}
- C. [1, 3] ['a', 'b'] {0, 1, 2}
- D. [1, 3] ['1', '2'] {3, 4, 5}
Correct answer: A. [1, 3] ['1', '2'] {0, 1, 2}
The odd numbers below 5 are 1 and 3. isdigit keeps the digit characters, and the set of remainders mod 3 is {0, 1, 2}. Integers hash to themselves, so the set prints in that order.
More Python Programming questions
- What is printed? python print(str(()), str([()]), repr(('a',)), str(('a', 1)))
- What is printed? python x = 10 def f(): return x x = 20 print(f(), (lambda y=x: y)(), [lambda: i for i in range(2)][1]())
- What is printed? python print(list(map(int, '1 2 3'.split())), list(map(str.upper, 'ab')), sum(map(int, '9' 3)) % 7)
- What is printed? python print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 1e-5, '%G' % 1e-10)
- What is printed? python print(max([1, 2], [1, 2, 0]) == [1, 2, 0], min((1, 'a'), (1, 'b')), sorted([(1, 'b'), (1, 'a')])[0][1])
- What is printed? python print(3 [0] == [0, 0, 0], [0] 3 is [0] 3, 'a' in 'abc' in 'abcdef')