gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:50:02 25 4
gpt4 key购买 nike

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

print "Unexpected error:", sys.exc_info()[0]

最佳答案

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

>>> def test():
... return ['item0', 'item1']
...
>>> test()
['item0', 'item1']
>>> test()[0]
'item0'
>>>

关于python - 将 [0] 附加到 python 中的方法有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14382038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com