🤔 What do the "yield" 🌱 and "return" 🔙 keywords do in Python?

The yield and return keywords in Python are used to control the flow of a function and return values or objects to the caller. "yield" create an iterator or generate a sequence of values on the fly while "return " terminate the function and return a single value.

Examples

  • Use yield to generate a sequence of values dynamically, such as the values of a Fibonacci sequence.

Article content

  • Use return to return the result of a function, such as the sum of two numbers or the average of a list of numbers.

Article content



To view or add a comment, sign in

More articles by Rao Abdul Jabbar Khan

Insights from the community

Others also viewed

Explore topics