标签:open lex 表达式 列表 pytho 有一个 encoding end print
x = 10
res = ‘ok‘ if x > 3 else ‘no‘
print(res)
#列表解析
l = [‘egg%s‘%i for i in range(10)]
print(l)
l = [‘egg%s‘%i for i in range(10) if i > 5]
print(l)
names = [‘alex_sb‘,‘egon‘,‘wupeiqi_sb‘,‘yuanhao_sb‘]
names_new = [name for name in names if name.endswith(‘sb‘)]
print(names_new)
#生成器表达式
g = (‘egg%s‘%i for i in range(10))##将中括号变成小括号即为生成器表达式
#迭代器同一时间在内存中只有一个值
print(g)
print(next(g))
print(next(g))
with open(‘db.txt‘,encoding = ‘utf-8‘) as f:
g = (len(line) for line in f)
print(max(g))
标签:open lex 表达式 列表 pytho 有一个 encoding end print
原文地址:http://www.cnblogs.com/llhtjwq/p/7511734.html