list官方文档:
Lists are mutable sequences, typically used to store collections of homogeneous items (where the precise degree of similarity will vary by application).
class list([iterable])
- Lists may be constructed in several ways:
Using a pair of square brackets to denote the empty list: []
Using square brackets, separating items with commas: [a], [a, b, c]
Using a list comprehension: [x for x in iterable]
Using the type constructor: list() or list(iterable)
- Lists may be constructed in several ways:
generator本身就是一个iterator,所以肯定是iterable的。
eg:
def take (n):
for i in range(n):
yield i
l = list(take(4))
>>> l = [0,1,2,3]