1. Advanced features of functions
1) List comprehensions, list comprehensions are List Comprehensions, which are very simple but powerful built-in comprehensions in Python that can be used to create lists.
eg:
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> L = []
>>> for x in range(1, 11): ... L.append(x * x) ... >>> L [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
But the loop is too cumbersome, and the list comprehension can replace the loop with one line to generate the above list:
>>> [x * x for x in range(1, 11)] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
2) 生成器
3) 迭代器
坚持跟更新