Didn't got that "yield" thing , kindly help

Hey there, i dont get the yield thing.

Why we use while and why there is no requirement of returning anything?

As Jatin bhaiya did:

prev , curr = curr , prev + curr

How the values changes i.e why firstly the value of prev changes to curr and then the value of curr becomes 2*curr?

pls explain in details.

Thank you

hey @varshneynishu2017 ,
first moving to yield thing.

There are two methods in python to return something , return and yield.
return call means that we need to end the function or loop anything at that point , and the yield means that the value needs to be send forward without stopping or pausing the current loop.

now the other doubt
prev , curr = curr , prev + curr

this code line is done multiple steps .
Python reads code from left to right and as it is a video declaration work.
Then firstly from left we get variable prev , so python will go to variable that is on the other side of equalize method.
So you will get it
1. prev = curr
2. curr = prev + curr

In this way , the main code line will be implemented in python.
So i guess now you can understand in what way is getting in the python.

so after first step , the prev becomes curr.
and then curr becomes prev + curr -> curr = curr+curr -> curr = 2*curr

So , in this the things happen in python , this small single code , would be actually a 2 line code if you would have implemented in that way.

that is the problem na, we don’t want the curr as 2*curr . We want it as prev + curr only and prev as currr.

hope you understand my issue. Else you can call me on 9536210514 :smile:

And while using yield and looping also why we have to use the next()?

hey @varshneynishu2017 ,
i am really sorry for this , it was my fault , i understood it wrong too.
I just clarrified this and it is like this ,
While we are in any such equalizing task ( having = in between ) , we first check from right to left whether there are no other such binary operations. and if there are any such , then they will operated first and assigned into a temporary variable.

So , moving from right to left we will get it like ,
a,b = b,a+b ,
we get a+b first , so it will assigned to a temp variable like temp=a+b and

a,b=b,temp and then the same happens ,
a=b
b=temp

In this way the whole instruction works in three steps as
temp = a+b
a=b
b=temp

In this way you will get the exact results as you want them to be.

Actually using an yield results in generator , which is actually an implemented as an iterable.
So to get values out of it you need to iterate over this generator using next() function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.