python - 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
解决方案
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())
推荐阅读
- sql - Redshift 或 ANY SQL:更新具有相似行且时间在 30 秒内的表
- bash - 无法从单行命令回显 bash 变量
- javascript - Object.create({}) 之间的区别 {}
- primefaces - Mojarra 上的 PrimeFaces TreeTable 问题
- sql - 根据 Teradata SQL 中另一列的最大值查找列计数
- sql - 将带有内部连接的更新查询从 vba 转换为 SQL Server
- php - preg_match_all 返回空数组
- java - 如何根据 Spinner 的选择将纯文本视图添加到当前布局?
- python - 什么是 Python 等价于 C# 的 ContinueWith()
- javascript - 使用 apache cordova 在服务器上上传多个视频和图像