>>> import os >>> [d for d in os.listdir(r"d: emp")] ['0.png', '0.xml', '01.png', 'performance'] >>> [x * x for x in range(1, 11) if x % 2 == 0] [4, 16, 36, 64, 100] >>> [m + n for m in "AB" for n in "CD"] ['AC', 'AD', 'BC', 'BD']
字典的遍历:
>>> d = {'x': 'A', 'y': 'B', 'z': 'C' } >>> for k, v in d.iteritems(): ... print k, '=', v ... y = B x = A z = C