I am trying to understand the below methodology,
In [26]: def generator():
....: print 'generator function hits'
....: for i in range(3):
....: yield i
....:
In [27]: def normal():
....: print 'normal function hits'
....: return range(3)
....:
In [28]: gen = generator()
In [29]: type(gen)
Out[29]: generator
In [30]: fun = normal()
normal function hits
In [31]: type(fun)
Out[31]: list
Here my research from the above code,
26 is the generator()
function and 27 is the normal()
function, when I have assigned generator()
function to gen variable I haven't seen any print message like generator function hits, But if I have assigned the normal()
function to fun variable, I have seen the print message like normal function hits. My question is why generator() function not hit ?