[Tutor] Difference between 'yield' and 'print'

raghu raghu vgvr620034 at gmail.com
Wed Jan 17 07:57:27 CET 2007


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:
the script is given below:
def fib(n):
    a,b = 0,1
    while a<=n:
       print a
       a,b = b,a+b

for x in fib(4):
    print  x. When i executed this script i am getting this error:
Typeerror:"nonetype" is not iterable
But the same script if 'print' is replaced with 'yield' inside while loop it
is executing properly without any type errors
could any one reply why print cant be used instead of yield and why error is
generated?

-- 

                                           Vanam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070117/796957ce/attachment.html 


More information about the Tutor mailing list