【问题标题】:How to return (and print) multiple values in a function?如何在函数中返回(和打印)多个值?
【发布时间】:2021-01-26 22:30:33
【问题描述】:

这是我的代码:

async def random():
    return 1, 2
idk1, idk2 = random()
print(idk1, idk2)

运行后报错:cannot unpack non-iterable coroutine object。我怎样才能解决这个问题?谢谢!

【问题讨论】:

标签: python-3.x


【解决方案1】:

我使用了 asyncio.run

import asyncio
async def random():
    return 1, 2
idk1, idk2 = asyncio.run(random())
print(idk1, idk2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 2020-01-29
    • 2015-12-01
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多