What is the output of the following? “`python import asyncio async def fetch(n): await asyncio.sleep(0) return n * 2 async def main(): results = await asyncio.gather(fetch(1), fetch(2), fetch(3)) print(results) asyncio.run(main()) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python import asyncio async def fetch(n): await asyncio.sleep(0) return n * 2 async def main(): results = await asyncio.gather(fetch(1), fetch(2), fetch(3)) print(results) asyncio.run(main()) “`

Key points

  • `asyncio.gather()` collects results in the order of function calls
  • The `fetch()` functions return values multiplied by 2
  • The output is a list of the results in the order they were called

Ready to go further?

Related questions