将[0]附加到python中的方法有什么作用?

Pyt*_*ner 2 python

将[0]附加到python中的方法有什么作用?例如,在下面的[0]中附加了一个方法.

print "Unexpected error:", sys.exc_info()[0]
Run Code Online (Sandbox Code Playgroud)

Cra*_*den 7

它调用方法并从返回的值中获取第0个元素.

>>> def test():
...   return ['item0', 'item1']
...
>>> test()
['item0', 'item1']
>>> test()[0]
'item0'
>>>
Run Code Online (Sandbox Code Playgroud)