Vidyalelo
Python · Q23

Generators and Iterators

Programming · Python · question 23

Q23

How is a coroutine defined in Python using the async keyword?

A.
coroutine def
B.
def coroutine
C.
async def
Answer
D.
def async

Answer: Option C

Solution

Answer: Option C
Solution:
The correct answer is Option C: async def.
In Python, a coroutine is defined using the async def syntax. This keyword combination indicates to the interpreter that the function is a coroutine, allowing it to use asynchronous features such as await expressions and yield statements within the function body. The async def syntax is specifically designed for defining coroutines, providing a clear and concise way to declare asynchronous functions in Python.