Special Method Protocols
__await__() — async protocol
Return an iterator implementing the awaitable protocol. The iterator terminates with a return value that becomes the await expression result. Delegate to a coroutine iterator when appropriate; returning a coroutine object directly is invalid.
Formal Syntax & Structure
python syntaxpython
def __await__(self):Return Value
iterator
Await protocol iterator.
Working Example
Example Snippetpython
import asyncioclass Answer: def __await__(self): async def resolve(): return 7 return resolve().__await__()async def demo(): return await Answer()print(asyncio.run(demo()))