From 717610667b8cc2120e020774c73432c8d6610e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Fri, 4 Nov 2022 10:17:34 -0300 Subject: [PATCH] =?UTF-8?q?Introdu=C3=A7=C3=A3o=20=C3=A0s=20Generator=20fu?= =?UTF-8?q?nctions=20em=20Python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula91.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 aula91.py diff --git a/aula91.py b/aula91.py new file mode 100644 index 0000000..c050ea1 --- /dev/null +++ b/aula91.py @@ -0,0 +1,15 @@ +# Introdução às Generator functions em Python +# generator = (n for n in range(1000000)) + +def generator(n=0, maximum=10): + while True: + yield n + n += 1 + + if n >= maximum: + return + + +gen = generator(maximum=1000000) +for n in gen: + print(n)