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 iter() method do in an iterator?
Think about what an iterator needs to provide to be iterable.
Can you explain what yield does?
Consider what happens to function execution when yield is used.
What method is called to get the next item from an iterator?
Think about how we retrieve subsequent elements from a sequence.
True or False: Generators store all values in memory.
Consider what makes generators different from lists.
Create a custom iterator that counts down from a given number to zero. Describe how you would implement the iter() and next() methods.
Refer back to the CountDown example shared earlier.
Write a generator that yields Fibonacci numbers indefinitely until a certain number is reached. What would you do to ensure it stops?
Consider how you'd check for the upper limit within a continuous generator.
5 more questions in this section. Enroll free to practise them all.
Enroll free