[].append(x) behaviour

后端 未结 4 747
北荒
北荒 2021-01-23 07:21

This executes as I\'d expect:

>>>x=[]
>>>x.append(3)
>>>x
[3]

Why does the following return None?

&g         


        
4条回答
  •  一个人的身影
    2021-01-23 08:10

    The append method of lists returns None. It only modifies the list it is bounded to. Same will happen with:

    x = {}.update(a=3)
    

提交回复
热议问题