# Python's Generators and Yield
Generators in Python are a way to create iterators using the yield
keyword. Here’s an example:
def count_up_to(n): count = 1 while count <= n: yield count count += 1
for number in count_up_to(5): print(number)
Generators are memory-efficient and allow you to work with large datasets without loading them entirely into memory.
python -c "def count_up_to(n):\n count = 1\n while count <= n:\n yield count\n count += 1\nfor number in count_up_to(5):\n print(number)"