What is difference between Yield and return Keyword in Python
Yield Keyword In Python :
Return sends/return specific value back to its caller function whereas Yield can produce a sequence of values. we can use yield when we want to iterate over a sequence but don't want to store the entire sequence in the memory
Yield are used in python generator. A generator function is defined as a normal function but whenever it needs to generate a value, yield is used instead of return.
if any function contains a yield then it will automatically become a generator function
Return sends/return specific value back to its caller function whereas Yield can produce a sequence of values. we can use yield when we want to iterate over a sequence but don't want to store the entire sequence in the memory
Yield are used in python generator. A generator function is defined as a normal function but whenever it needs to generate a value, yield is used instead of return.
if any function contains a yield then it will automatically become a generator function
Comments
Post a Comment