Quiz on Generators in Python
Q.1. Which keyword is asociated with generators?
Q.2. What keyword is used to define a generator?
Q.3. On which generator cannot be used?
Q.4. Which keyword is used to iterate through a generator?
Q.5.What object is created when a generated is called?
Q.6. The keyword used for returning individual items of the generator is
Q.7. Minimum number of yield statements required in a generator?
Q.8. What is the output of following program?
def gen():
yield 'a'
yield 'b'
yield 'c'
x=gen()
for i in x:
print(i,end="")
Q.9. What is the output of following program?
def gen():
for i in range(5,0,-1):
yield i
while next(gen()):
print(next(gen()))
Q.10. What is the output of following program?
def gen():
yield 1
yield 2
yield 3
x = gen()
print(next(x),next(x),next(x))
Q.11. What is the output of following program?
def gen():
yield 1
yield 2
yield 3
x = gen()
print(x[1])
Q.12. What is the output of following program?
l = [1,3,5,7,9]
value = sum(x for x in l)
print(value)
Q.13. What is the output of following program?
def gen():
a = 5
while a:
yield a
a -= 1
for i in gen():
print(i, end=" ")
Q.14. What is the output of following program?
def rev(str):
length = len(str)
for i in range(length - 1, -1, -1):
yield str[i]
for char in rev("hello world"):
print(char,end="")
Q.15. Generator in Python is not a subclass of Iterator.
Instructions:-
- This Quiz is based on Generators in Python
- Each correct answer will carry 2 points
- Once an option is selected you cannot select any other, So choose wisely
- Do not refresh the page as it will reset the quiz
- Once the time is up the quiz will automatically get submitted with no of Question responded
- Your total score alongwith your name will be shown after submission of the Quiz
- Wish you ALL THE BEST 👍👍
START
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP