ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
print([i for i in range(10) if i % 3 == 0][::-2])
- A. [9, 6, 3, 0]
- B. [9, 3, 0]
- C. [6, 0]
- D. [9, 3]
Correct answer: D. [9, 3]
The comprehension gives 0, 3, 6 and 9, and the slice with step -2 starts at the end and skips every other item, which gives 9 and 3.
More Python Programming questions
- What is printed? python print(set('mississippi') == set('misp'), len(set('mississippi')))
- What is printed? python print(0.1 3 == 0.3, abs(0.1 3 - 0.3) < 1e-9)
- What is printed? python a = [1, 2, 3] print(a[3:], a[1:10], a[-10:1])
- What is printed? python print(len(bytes('é', 'utf-8')), len('é'))
- What is printed? python print(float('inf') > 10308, -float('inf') < -10308)
- What is printed? python print(sorted({3: 'a', 1: 'b'}), list(reversed(sorted({3: 'a', 1: 'b'}))))