[英]Why when I extend a list does it have 'NoneType' as type?
I am looking to extend a list and have the following我正在寻找扩展列表并具有以下内容
ListA = list(x)
ListB = list(y)
ListC = ListA.extend(ListB)
This gives ListC
as having <type 'NoneType'>
and I am wondering why this isn't just a list as well.这使
ListC
具有<type 'NoneType'>
并且我想知道为什么这不仅仅是一个列表。
Thanks!谢谢!
extend
, like many other list operations, operates in-place and returns None.与许多其他列表操作一样,
extend
就地操作并返回 None。 ListA
is modified with the extra elements. ListA
用额外的元素进行了修改。
You did not define ListC as a list type.您没有将 ListC 定义为列表类型。
As you know, list() is a function;如您所知,list() 是一个函数; which generates a list type.
它生成一个列表类型。
list.extend does not. list.extend 没有。 Instead, it modifies the given list.
相反,它会修改给定的列表。
Look at your code again.再看看你的代码。
ListA = list(x) ## You defined ListA as a list type; with list(x).
ListB = list(y) ## You defined ListB as a list type; with list(y).
ListC = ListA.extend(ListB) ## ListC is not defined as a list type.
Therefore, ListC returns NoneType.因此,ListC 返回 NoneType。
It is good that you noticed the difference between + and list.extend().很高兴您注意到 + 和 list.extend() 之间的区别。 Keep it up and good luck.
坚持下去,祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.