Why does [].append() not work in python?

后端 未结 3 1783
耶瑟儿~
耶瑟儿~ 2020-12-07 01:11

Why does this work -

a = []
a.append(4)
print a

But this does not -

print [].append(4)

The output in se

3条回答
  •  萌比男神i
    2020-12-07 01:53

    The method append returns no value, or in other words there will only be None

    a is mutable and the value of it is changed, there is nothing to be returned there.

提交回复
热议问题