TypeError与函数

hol*_*sor 0 python python-3.x

我正在尝试定义一个函数,该函数返回没有该列表中第一个和最后一个项的列表.但是,当我运行该函数时,我得到了这个:"TypeError:'builtin_function_or_method'对象不支持删除项目".

到目前为止这是我的代码:

def middle(t):
    """returns a copy of a list with the first and last items removed

    list -> list"""
    t = input
    del t[0]
    del t[-1]
    print(t)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

Mar*_*nen 6

t=input正在分配t给功能对象input.你不能切片功能. t[1:-1]将返回一个新列表,其中删除了第一个和最后一个项目.