Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
What does the yield keyword do in Python?
Think about how a function can pause and return multiple values.
How do you call a generator function?
Consider how you use parentheses to call functions.
What does the yield keyword do in a function?
Think about what happens after yield is called.
True or False: A generator function can only yield once.
Consider how a function can pause at multiple points.
Implement a generator function that yields a Fibonacci sequence indefinitely until stopped.
Think about how the Fibonacci sequence is formed by summing the last two numbers.
Create a generator that reads lines from a text file and yields them one at a time.
Consider how to open a file and iterate through its lines.
5 more questions in this section. Enroll free to practise them all.
Enroll free