标签:三层 range == 循环 abc strong for循环 使用 判断
>>>[x*x for x in range(5)]
[0, 1, 4, 9, 16, 25]
>>>[m+n for m in ‘ABC‘ for y in ‘XYZ‘]
[‘AX‘, ‘AY‘, ‘AZ‘, ‘BX‘, ‘BY‘, ‘BZ‘, ‘CX‘, ‘CY‘, ‘CZ‘]
三层或三层以上的循环较少用到
>>> [x for x in range(1, 11) if x % 2 == 0]
[2, 4, 6, 8, 10]
>>> [x if x % 2 == 0 else -x for x in range(1, 11)]
[-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]
标签:三层 range == 循环 abc strong for循环 使用 判断
原文地址:https://www.cnblogs.com/ShineMiao/p/13995445.html