List comprehension


#1

@ronit1710 could u plss explain the (x ** 2) % 2 == 0 part of the code, im new to programming and i didnt understand your explanation.


5/17 List Comprehension Syntax Help Please!
#2

it check if the square of x is even (divislby by 2)


#3

(x ** 2) % 2 == 0

x is being squared and divided to by 2.

What any number gives when it get divided by 2 and what does this test is done?
This is done to check if number is Even (as fellow coder has mentioned)

This gives a remainder (% returns remainder here.)

== is a comparison operator that checks if this remainder is equal to 0.

I hope it helps. :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.