Hi,
Why is the generator expression after IF statement always return True? Is it because the if statement only checks whether there is a new value "generated" by the expression, if so, then it will return True? But the below expression (a>100 for in x) will not generate a new value, will it?
For example:
The result is
Thanks in advance!
Why is the generator expression after IF statement always return True? Is it because the if statement only checks whether there is a new value "generated" by the expression, if so, then it will return True? But the below expression (a>100 for in x) will not generate a new value, will it?
For example:
1 2 3 |
x = [ 1 , 2 , 3 , 4 , 5 ] y = [a * * 2 for a in x if (a> 100 for a in x)] print (y) |
1 |
[ 1 , 4 , 9 , 16 , 25 ] |