pyhton 解析式

列表解析式

lst1 = list(range(10))
lst2 = [item + 100 for item in lst1]
print(lst2)

带条件判断的列表解析式, item满足被2整除,被3整除

lst3 = [item + 100 for item in lst1 if item % 2 == 0 and item % 3 == 0]
print(lst3 )

集合解析式

set1 = {(x,x+1) for x in range(10)}
print(set1)

字典解析式

dict1 = {'{}'.format(x):x for x in range(10)}
print(dict1)

你可能感兴趣的:(pyhton 解析式)