Python的坑(2) -- TypeError: 'builtin_function_or_method' object is not subscriptable

类似问题链接:

1. http://bbs.pythontab.com/forum.php?mod=viewthread&tid=2541&page=1&extra=

2.http://bbs.csdn.net/topics/360213400


import string



def sm():
    dict ={}
    keys = string.ascii_lowercase + string.ascii_lowercase
    values = string.ascii_lowercase + string.ascii_lowercase
    for key in keys:
        dict[key] = values[keys.index[key] + 3]

    return dict


运行后:

>>> s1 = sm()


Traceback (most recent call last):
  File "", line 1, in
    s1 = sm()
  File "D:\github.com_henry199101\6.00.1x_Files\Week_6\Problem_Set_6\caogao\qwer.py", line 8, in sm
    dict[key] = values[keys.index[key] + 3]
TypeError: 'builtin_function_or_method' object is not subscriptable

内建函数或者方法对象不能subscriptable

错误在index[key],原因是:index后应当是()

你可能感兴趣的:(Python的坑,Python,对象,函数,Python,Python的坑)