What is the output of `[x for x in range(5) if x != 3]`?

Python Professional Hard

Python Professional — Hard

What is the output of `[x for x in range(5) if x != 3]`?

Key points

  • List comprehension filters out the number 3 from the range.
  • The resulting list contains all numbers from 0 to 4 except 3.
  • The condition `if x != 3` ensures that only numbers not equal to 3 are included.

Ready to go further?

Related questions