What is the output of the following? “`python result = [x**2 for x in range(5) if x % 2 == 0] print(result) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python result = [x**2 for x in range(5) if x % 2 == 0] print(result) “`

Key points

  • List comprehension is used to create a new list based on existing elements.
  • The condition `if x % 2 == 0` filters out numbers that are not divisible by 2.
  • The `x**2` squares each number before adding it to the list.

Ready to go further?

Related questions