def test():
    ls=[1,2]
ls = [1,2,3]
test()
print(ls)

输出仍然是 [1,2,3]

def test():
    if not ls:
        return
    print(ls)
    ls.pop()
    test()
ls = [1,2,3]
test()
print(ls)

输出为 []

在函数中将ls=[1,2],对于list而言是引用,对应于c语言中的指针。所以返回函数后还是[1,2,3]

但是在函数中pop() ls,可以认为将ls看作全局变量,在函数中对他进行操作。