如何从Python中的函数返回多个值?
如何从Python中的函数返回多个变量?
How to return more than one variable from a function in Python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何从Python中的函数返回多个变量?
How to return more than one variable from a function in Python?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可以用逗号分隔要返回的值:
逗号表示它是一个元组,因此您可以用括号将您的值括起来:
然后,当您调用该函数时,您 a) 将所有值作为元组保存到一个变量中,或 b) 分开你的变量名用逗号分隔
You separate the values you want to return by commas:
The commas indicate it's a tuple, so you could wrap your values by parentheses:
Then when you call the function you a) save all values to one variable as a tuple, or b) separate your variable names by commas
这也是处理结果的代码:
Here is also the code to handle the result:
作为元组返回,例如
Return as a tuple, e.g.