Python - Extending a list directly results in None, why?

后端 未结 2 1680
轮回少年
轮回少年 2020-12-21 19:27
x=[1,2,3]
x.extend(\'a\')

Output:

x is [1,2,3,\'a\']

But when I do the following:

[1,2,3].extend(\'a\         


        
2条回答
  •  北海茫月
    2020-12-21 20:04

    extend will extend list it self. Return type of that method is None

    If you want to union 2 list and add that list to another list then you have to use another way to add.

    listB[15:18] = listC[3:12]
    listA.extend(listB)
    

提交回复
热议问题