gpt4 book ai didi

python - Python 中的列表和迭代器有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 18:13:45 25 4
gpt4 key购买 nike

<分区>

我正在看书Think Python: How to think like a computer scientist ,它表示在 Python 3.x 中,dict([list of tuples]) 返回一个 iterator 而不是 list(就像Python 2.7 中的情况)。

书上没有进一步解释,弄得我一头雾水。我特别想知道:

  1. 迭代器和列表有何不同,以及

  2. 通过列表返回迭代器有什么好处?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com