ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(len({(i, j) for i in range(3) for j in range(3) if i <= j}))
  1. A. 5
  2. B. 6
  3. C. 9
  4. D. 3

Correct answer: B. 6

The pairs with i <= j among 0, 1, 2 are (0,0), (0,1), (0,2), (1,1), (1,2) and (2,2), which makes 6 distinct tuples.

More Python Programming questions

Exams that ask this topic