首页 > 解决方案 > Python async functions

问题描述

Hey I am kinda new to the all deal of async functions and await and all this other stuff and I am having a hard time learning it. So my question is how do I save / return and save into a variable some calculated data from a function ?

I tried to do :

x = 0

async def func(name): x = name

标签: pythonasynchronousasync-await

解决方案


Just like a synchronous function.

Example:

import asyncio

async def addition(lnum, rnum):
    sum = lnum + rnum
    return sum

async def main():
    var = await addition(1, 1)
    print(var) #2

asyncio.run(main())

推荐阅读