Define a Coroutine
Advanced · Write the code · 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 lessonWrite an async def function called greet that takes a name parameter and returns the string Hello, <name>! Welcome to async Python. (where <name> is replaced with the argument). Then, outside the function, print the type of the object returned by calling greet('World') (do NOT await it).
# Define an async function called greet
More Async and Await exercises
- Predict the Coroutine OutputAdvanced
- Build an Async IteratorAdvanced
- Fix the Async BugAdvanced
- Gather Concurrent ResultsAdvanced
- Refactor to Async PatternAdvanced
All Python exercises · 50 practice problems · Advanced Python quiz