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

版权声明:本文为博主原创文章,可以转载,但转载前请联系博主。 https://blog.csdn.net/qq_33528613/article/details/72807132

类似问题链接:

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 "<pyshell#14>", line 1, in <module>
    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后应当是()

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页