Feb-13-2018, 06:59 AM
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:
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:
x=[1,2,3,4,5] y=[a**2 for a in x if (a>100 for a in x)] print(y)The result is
[1, 4, 9, 16, 25]Thanks in advance!