Examveda

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.

This Question Belongs to Python Program >> Generators And Iterators

Join The Discussion

Related Questions on Generators and Iterators