- 3
Why we use yield in python generators where print function can be used
3 Respostas
+ 2
There is whole lot of information available on internet about the purpose of yield ,you should go through that and then ask a specific question if you feel like you don't understand something ,if you use print it won't be a generator anymore so I can't tell what do you exactly wanna know ,
+ 1
print outputs there itself but yield return value in iterable way..
And Apart from that way, also yield has advantages for generators..
+ 1
To facilitate multiple outputs!
Since the return statement can only give one output,
We use yield for multiple outputs