python學習筆記(7)-高級特性(三)-列表生成式與生成器

1. 列表生成式 列表生成式即List Comprehensions,是python內置很是簡單卻強大的能夠用來建立list的生成式。 如: >>> range(1,11) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> L = [] >>> for i in range(1,11): ...     L.append(i * i) ...  >>> L [1, 4, 9,
相關文章
相關標籤/搜索