Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
How do you send a value into a generator?
It’s like `next()`, but allows passing a value inside.
What must you do before you can send a value to a generator?
The generator needs to be paused at a yield to receive a value.
What value must be sent into a generator to start it before any values can be sent?
This primes the generator.
True or False: You can use .send() to both resume a generator and send a value to it.
It’s a combination of next() and sending data.
Create a generator that calculates running averages. It should accept numbers sent into it and yield the current average after each number.
Use number = yield average pattern.
Write a generator that accepts commands sent via .send() to either "add", "subtract", or "reset" an internal counter and yields the current count after each command.
Use command = yield count and handle each command.
6 more questions in this section. Enroll free to practise them all.
Enroll free