What is a coroutine in Python?
A. A specialized class for iteration
B. A generator with two yield statements
C. A function that can yield control and later resume
D. A function that only returns values
Answer: Option C
Solution (By Examveda Team)
The correct answer is Option C: A function that can yield control and later resume.A coroutine in Python is a function that can yield control back to the caller and later resume execution from the point it left off. Unlike regular functions, which execute to completion and return a single value, coroutines can yield values using the yield statement, allowing for cooperative multitasking and asynchronous programming. Coroutines are commonly used in asynchronous frameworks like asyncio to handle concurrent execution and manage asynchronous tasks efficiently.
What is a generator in Python?
A. A function that generates random numbers
B. A special type of list
C. A way to define classes
D. A function that yields values one at a time
How is a generator different from a regular function?
A. A generator uses the return keyword
B. A generator can yield multiple values
C. A generator uses the break statement
D. A generator uses the continue statement
What is an advantage of using generators for large datasets?
A. They use more memory
B. They are slower than loops
C. They are easier to implement
D. They use less memory
How do you define a generator function in Python?
A. Using the generator keyword
B. Using the def keyword and yield statement
C. Using the gen keyword
D. Using the function keyword

Join The Discussion