What does this syntax mean in Python?

前端 未结 2 565
说谎
说谎 2021-01-22 02:28

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

resp, content = client.request(request_token_url, \"GET\")
2条回答
  •  迷失自我
    2021-01-22 03:20

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

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

    If you had just

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

    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].

提交回复
热议问题