将[0]附加到python中的方法有什么作用?例如,在下面的[0]中附加了一个方法.
print "Unexpected error:", sys.exc_info()[0]
Run Code Online (Sandbox Code Playgroud)
它调用方法并从返回的值中获取第0个元素.
>>> def test():
... return ['item0', 'item1']
...
>>> test()
['item0', 'item1']
>>> test()[0]
'item0'
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
310 次 |
| 最近记录: |