函数调用后的方括号

Joh*_*hnB 1 python

我是Python的新手,并且遇到了一段令我困惑的代码.

ts, pkt2 = capPort2.wait(1, 45)[0]
Run Code Online (Sandbox Code Playgroud)

前一行让我很困惑.我理解wait用两个参数调用函数,但是这[0]意味着什么呢?

Fre*_*ihl 5

它意味着通过函数提取列表/元组返回中的第一项.

In [1]: "this is a long sentence".split()
Out[1]: ['this', 'is', 'a', 'long', 'sentence']

In [2]: "this is a long sentence".split()[0]
Out[2]: 'this'
Run Code Online (Sandbox Code Playgroud)