x * x for x in range(1, 11) if x % 2 == 0这个式子运算顺序是怎样的?


Python的列表生成式?

python 新手问题

losstoY 11 years, 3 months ago

啊我知道了。。。。。


 for x in range(1,11):
if x%2==0
print x*x

LDKAKAK answered 11 years, 3 months ago


 res = []
for x in range(1,11):
    if x%2 == 0:
       res.append(x*x)

高機動型無節操 answered 11 years, 3 months ago


 python


 ret = []
for x in range(1, 11):
    if x % 2 == 0:
        ret.append(x)

工口君2010 answered 11 years, 3 months ago

就是这样子的,对于范围在1到11内的元素,如果它能被2整除就生成一个该元素的平方给你。建议你看看pthondoc文档。

风雨不同舟- answered 11 years, 3 months ago

Your Answer