Cannot append to a returned list?

前端 未结 4 1892
南旧
南旧 2021-01-21 19:36
def f():
    lst = [\'a\', \'b\', \'c\']
    return lst[1:]

why is f().append(\'a\') is None == True even though f().__class__

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 20:19

    Because append() returns None and not the list object. Use

    l = f()
    l.append('a')
    ...
    

提交回复
热议问题