Why do we use yield in Python?

We should use yield when we want to iterate over a sequence but don't want to store the entire sequence in memory. yield is used in Python generators. A generator function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return.

コメント

このブログの人気の投稿

シェルピンスキーの三角形

global 変数・ローカル変数