Is there any difference between yield and print in python script?i have written a script based on fibonacci series where in i used yield and print in two different scripts:<br>the script is given below:<br>def fib(n):<br>&nbsp;&nbsp;&nbsp; a,b = 0,1
<br>&nbsp;&nbsp;&nbsp; while a&lt;=n:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a,b = b,a+b<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>for x in fib(4):<br>&nbsp;&nbsp;&nbsp; print&nbsp; x. When i executed this script i am getting this error: Typeerror:&quot;nonetype&quot; is not iterable<br>But the same script if &#39;print&#39; is replaced with &#39;yield&#39; inside while loop it is executing properly without any type errors
<br>could any one reply why print cant be used instead of yield and why error is generated?<br clear="all"><br>-- <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vanam