三元表达式
条件成立时的返回值 if 条件 else 条件不成立时的返回值
a=10
b=20
res = a if a>b else b #三元表达式
print(res)
列表生成式:
l=[item**2 for item in range(1,11)]
print(l)
# l=[item**2 for item in range(1,5) if item > 2]
# print(l)
#常见的操作
# names=['alex','wxx','egon','lxx','zhangmingyan']
# l=[]
# for name in names:
# if name != 'egon':
# l.append(name + 'SB')
# names=l
# names=[name+'SB' for name in names if name != 'egon']
# print(names)
keys=['name','age','sex']
values=['egon',18,'male']
res=zip(keys,values)
print(list(res))
print(list(res))
d={}
for k,v in zip(keys,values):
d[k]=v
print(d)
keys=['name','age','sex']
values=['egon',18,'male']
d={k:v for k,v in zip(keys,values)}
print(d)
# 生成器表达式
# g=(i for i in range(10))
# # print(g)
#
# print(next(g))
# print(next(g))
# nums=[11,22,33,44,55]
# print(max(nums))
# with open('a.txt',encoding='utf-8') as f:
# nums=(len(line) for line in f)
# print(max(nums))
# print(max(nums))
# print(max(nums))
l=['egg%s' %i for i in range(100)]
print(l)
g=('egg%s' %i for i in range(1000000000000))
# print(g)
print(next(g))
print(next(g))