Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 33)
33.
How can you implement a generator that produces a sequence of powers of 2?
Using a loop with a yield statement
By calling a recursive function with yield
Using a list comprehension with yield
By using the itertools.cycle() function
Answer: Option
Explanation:
A generator for a sequence of powers of 2 can be implemented using a loop with a yield statement.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.