From 9032feca0bd711b2697114ffa9801a1b2d02f7b8 Mon Sep 17 00:00:00 2001 From: Hizenberg469 Date: Mon, 24 Mar 2025 16:00:37 +0000 Subject: [PATCH] generator done --- debugging/__pycache__/pdb.cpython-312.pyc | Bin 0 -> 390 bytes debugging/pdb.py | 7 ++++ debugging/wiki.txt | 0 generators/fibonacci.py | 11 ++++++ generators/generator.py | 22 ++++++++++++ generators/special_for.py | 10 ++++++ generators/wiki.txt | 42 ++++++++++++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 debugging/__pycache__/pdb.cpython-312.pyc create mode 100644 debugging/pdb.py create mode 100644 debugging/wiki.txt create mode 100644 generators/fibonacci.py create mode 100644 generators/generator.py create mode 100644 generators/special_for.py diff --git a/debugging/__pycache__/pdb.cpython-312.pyc b/debugging/__pycache__/pdb.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e3a1babd7b73247d4b1880d6a0b170549781e835 GIT binary patch literal 390 zcmX@j%ge<81eqES(i4F6V-N=hSfGs0DnQ0`h7^Vr#vFzyh7_h2hA2iRhE&EB<`kCI zOb}I!43&(UtS>&W2_sk(NMs?af(ovN(u@o>3^j~ZKwdC| zCZnGw(=FzLl%!jn#i=FnB}IwJsX!5yywY4lFlkf_GD<<=myUi$er~FMR%u>piGD$4 zNk)F2Zb@lLeo What are generators? + + Generators are used to generate range of values + without using extra space. + + for example, range(1,100) creates number from 1 to + 100 but in this the procedure is as follows: + + -> initialize with value 1. + -> returns the value. + -> increment it by one. + -> Repeat this same process from step 2, + until all values are generated with + the given range. + + + * generators is a iterator but iterator + is not necessarily a generator. + +-> How to create your own generators? + + for ex: + + def generator_function(num): + for i in range(num): + yield i + + g = generator_function(10) + next(g) + next(g) + print(next(g)) + + Two keywords are used here: + -> yield: This is used to make functions a + generator. + + -> next: This is used to get the next value from + generator function + + Note that unlike creating a list and then returning + the range of values, generators don't take extra + space to have range of values. \ No newline at end of file