python 列表推导式if语句比较多,求详解
[ (x, y) for x in range(10) if x % 2 if x > 3 for y in range(10) if y > 7 if y != 8 ] 根据结果自己都能猜个七七八八 还有不明白的吗>>> [ (x, y) for x in range(10) if x % 2 if x > 3 for y in range(10) if y > 7 if y != 8 ]
[(5, 9), (7, 9), (9, 9)]
>>> [ (x, y) for x in range(10) if x % 2 andx > 3 for y in range(10) if y > 7 and y != 8 ]
[(5, 9), (7, 9), (9, 9)]
>>> lst=[]
>>> for x in range(10):
... for y in range(10):
... if x%2 and x>3:
... if y>7 and y!=8:
... lst.append((x,y))
...
>>> lst
[(5, 9), (7, 9), (9, 9)]
>>>
页:
[1]