如何在python中从列表中删除项目

如何在python中从列表中删除项目,python,list,Python,List,我尝试从列表中删除项目,从初始位置删除到最终位置: def remove_range(s,f): #this is the function for i in range(s, f): del numbers[i] #and this is in the main: if cmd.startswith("remove items"): try: n = input("") m = input("") int(n)

我尝试从列表中删除项目,从初始位置删除到最终位置:

def remove_range(s,f):   #this is the function 
    for i in range(s, f):
    del numbers[i]

#and this is in the main:
if cmd.startswith("remove items"):
    try:
        n = input("")
        m = input("")
        int(n)
        int(m)
        remove_range(n, m)

为什么此功能不起作用?

删除项目会将以下列表项目上移1。假设你有10个项目,删除3,4,5。真正发生的是,删除3、4,然后再上一班。然后删除4时,实际上是在删除原来的5。幸运的是,列表切片解决了这个问题

del numbers[s:f]

你可以用这个符号

del numbers[s:f]

这不是一个列表。嗯。。。我一直认为切片是列表理解的一部分。我会改的,不一定是n-1或m-1