我在GeeksforGeeks上找到了这个例子:
tab = {'geeks': 4127, 'for': 4098, 'geek': 8637678}
# using format() in dictionary
print('Geeks: {0[geeks]:d}; For: {0[for]:d}; '
'Geeks: {0[geek]:d}'.format(tab))
我尝试取出位置索引“ 0”并像这样运行并得到错误:
>>> print('Geeks: {[geeks]:d}; For: {[for]:d}; Geeks: {[geek]:d}'.format(tab))
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print('Geeks: {[geeks]:d}; For: {[for]:d}; Geeks: {[geek]:d}'.format(tab))
IndexError: tuple index out of range
我不太了解此错误消息的含义。任何帮助表示赞赏。