ProgrammingModerateAccenture pattern

What is printed?

What is printed?
print({x % 3 for x in range(10)})
  1. A. {0, 1, 2}
  2. B. {0, 1, 2, 3}
  3. C. {1, 2, 3}
  4. D. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

Correct answer: A. {0, 1, 2}

x % 3 for x in 0..9 can only ever be 0, 1 or 2, and a set keeps each distinct result once, giving {0, 1, 2} regardless of how many x values produced each remainder.

More Python Programming questions

Exams that ask this topic