sum(list[range(40)]) #速度比下面的慢 sum(x ** 2 for i in xrange(4))
name = ‘pang‘ res = ‘is‘ if name == ‘pang‘ else ‘chun‘ print(res)
三元运算列表解析
l = [i for i in range(10)] l = [i for i in range(10) if i > 5] print(l)
l = (i for i in range(10)) #生成器表达式 print(l) print(l.__next__()) print(l.__next__()) print(l.__next__()) print(next(l)) print(next(l)) print(next(l))
原文地址:https://www.cnblogs.com/Essaycode/p/10105296.html
时间: 2024-10-08 13:27:38