作者:三心两意真实扭 | 来源:互联网 | 2023-10-12 14:45
Python2.7.14(v2.7.14:84471935ed,Sep162017,20:19:30)[MSCv.150032bit(Intel)]onwin32
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> b = [2,44,11,55,222]
>>> [m for m in b if m % 2 ==1] #取‘b’的奇数
[11, 55]
[m for m in ? if m %2 ==1] #为求奇数的运算法则 可以这样写 ‘?’ 号替换为想要取的字典 比如上面的‘b’
[m for m in ? if m %2 ==0] #为求偶数的运算法则 可以这样写 ‘?’ 号替换为想要取的字典 比如上面的‘b’