- 3

Why we use yield in python generators where print function can be used

12th Aug 2020, 12:10 PM
Known Stranger
Known Stranger - avatar
3 Antworten
+ 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 ,
12th Aug 2020, 12:32 PM
Abhay
Abhay - avatar
+ 1
print outputs there itself but yield return value in iterable way.. And Apart from that way, also yield has advantages for generators..
12th Aug 2020, 12:33 PM
Jayakrishna 🇮🇳
+ 1
To facilitate multiple outputs! Since the return statement can only give one output, We use yield for multiple outputs
12th Aug 2020, 12:50 PM
Namit Jain
Namit Jain - avatar