+ 2

Can someone pls explain me these codes?

https://code.sololearn.com/c6AheOkg0oEN/?ref=app

25th May 2020, 10:45 AM
Bhavuk Sharma
Bhavuk Sharma - avatar
8 odpowiedzi
+ 6
HonFu after yield the programm returns the value. it is first the inner yield... it is evaluated first and after the outer one.. which evaluated to None. so... yes...
25th May 2020, 2:39 PM
Oma Falk
Oma Falk - avatar
+ 6
You have generator functions there. Whenever you call them, you get a generator object, that follows the code of the function body, usually handing out values one by one (in this case only one). * just unpacks any iterable, also generator objects, in one run, so that you can for example - as done here - print them out one by one. You should read/repeat the tutorial lesson about generators. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2462/
25th May 2020, 11:20 AM
HonFu
HonFu - avatar
+ 2
very tricky * makes the music it makes the generator iterate. without it only generator object is yielded/returned.
25th May 2020, 12:24 PM
Oma Falk
Oma Falk - avatar
25th May 2020, 3:41 PM
Oma Falk
Oma Falk - avatar
0
HonFu i mean yield (yield 5) so the yield 5 gives a generator and now yield (generator) gives None but when in another case the generator is yielding 4 when yielding the value
25th May 2020, 1:41 PM
Bhavuk Sharma
Bhavuk Sharma - avatar
0
Hm. Is yield (yield 5) synonymous with this? yield 5 yield
25th May 2020, 1:47 PM
HonFu
HonFu - avatar
0
HonFu Oma Falk in code 1 yield (yield 5) how it will be processed if yield 5 in bracket is processed than the o/p will be a generator object stored somewhere so now as the yield 5 is giving generator object and which is followed by another yield function so now yield (generator) generator is the o/p of yield 5 than it is giving None but in code 2 star() is yielding a generator object too which in another function is followed by another yield (generator_object) o/p of star function but the o/p in both the case are different one is giving 4 and another is giving None while processing 2nd yield
25th May 2020, 3:30 PM
Bhavuk Sharma
Bhavuk Sharma - avatar
0
sorry not 4 but giving generator objects location
25th May 2020, 3:31 PM
Bhavuk Sharma
Bhavuk Sharma - avatar