In Python, I have many times seen the yield
function used to create a generator. Both this and the print
function technically both perform the action of methods because they return a value. However, during the change from Python 2 to Python 3, the print
function gained parentheses like a normal method call, but yield stayed the same. Also, yield
gains a yellowish color of a reserved keyword while print
is the purple of a reserved method. Why is yield
not considered a method and colored this way along with not using parentheses syntax?
(In a similar vein, why does return
also lack parentheses?)
Let me add some more stuff, yield and continue are not given parentheses in many other languages as well. I just wanted to know what makes it different other than it is reserved. There are many other reserved methods out there which get parentheses.
return
– Elurd