async — Easy Playground
Declares an asynchronous coroutine function or context manager
Python Playground
import asyncio
async def greet(name):
print(f"Hello, {name}!")
return f"Greeted {name}"
# Run the async function
result = asyncio.run(greet("Python"))
print(f"Result: {result}")
# Async with await
async def fetch_data():
print("Fetching...")
await asyncio.sleep(0) # simulate async work
print("Done!")
return [1, 2, 3]
data = asyncio.run(fetch_data())
print(f"Data: {data}")
Output
Click "Run" to execute your code
async def creates a coroutine function. Calling it returns a coroutine object that must be awaited or run with asyncio.run().
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?