Programming Languages
Python
Subjective
Sep 30, 2025
How do you create and use a generator function? Provide an example.
Detailed Explanation
def fibonacci_gen(n):\n a, b = 0, 1\n for _ in range(n):\n yield a\n a, b = b, a + b\n\n# Usage: for num in fibonacci_gen(5): print(num)
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts