Predict the Coroutine Output
Advanced · Predict the output · from Python Async/Await: Write Non-Blocking Code from Scratch
From the lesson: Python Async/Await: Write Non-Blocking Code from Scratch
Imagine you're a chef in a busy kitchen. You don't stand and watch the oven for 20 minutes while your pasta boils on another burner. Instead, you start the oven, move to the pasta, then check the salad -- all without waiting idle. That's exactly what asynchronous programming does for your code.
Read the lessonWhat does the following code print?
import asyncio
async def add(a, b):
return a + b
result = add(3, 4)
print(type(result).__name__)# Type what you think the output will be, then run to check
import asyncio
async def add(a, b):
return a + b
result = add(3, 4)
print(type(result).__name__)
More Async and Await exercises
- Define a CoroutineAdvanced
- Build an Async IteratorAdvanced
- Fix the Async BugAdvanced
- Gather Concurrent ResultsAdvanced
- Refactor to Async PatternAdvanced
All Python exercises · 50 practice problems · Advanced Python quiz