这个语法在 Python 中是什么意思? [英] What does this syntax mean in Python?

查看:42
本文介绍了这个语法在 Python 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面声明中的逗号是什么意思?它是否一次定义了两个变量?

What does the comma in the declaration below mean? Does it define two variables at once?

resp, content = client.request(request_token_url, "GET")

推荐答案

它创建了一个 元组.在这种情况下,元组由两个变量组成,它们从 request() 获得结果.

It creates a tuple. In this case, the tuple is of two variables, which get assigned the result from request().

request() 返回一个元组,然后在赋值过程中自动解包到左边的元组中.

request() returns a tuple, which is then automatically unpacked into the left-hand tuple during assignment.

如果你刚刚

result = client.request(request_token_url, "GET")

将元组直接分配给结果.然后您将能够访问 result[0] 处的响应,即元组中的第一个值,内容将在 result[1] 中.

that would assign the tuple directly to result. Then you would be able to access the response at result[0], the first value in the tuple, and the content would be in result[1].

这篇关于这个语法在 Python 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆