What does appending [0] to methods in python do? For example, in the following [0] is appended to a method.
print "Unexpected error:", sys.exc_info()[0]
It calls the method and gets the 0th element from the returned value.
>>> def test():
... return ['item0', 'item1']
...
>>> test()
['item0', 'item1']
>>> test()[0]
'item0'
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With