C的逻辑思维通常是这么写的:
numbers = range(10)
evens = []
i = 0
while i < size :
if i % 2 == 0:
evens.append(i)
i += 1
evens
[0,2,4,6,8]
而用Python的逻辑思维是这么写的:
[ i for i in range(10) if i % 2 == 0 ]
大家明白为什么学Python了吧 !