简体   繁体   English

为什么当我扩展列表时,它的类型是“NoneType”?

[英]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.

相关问题 为什么我的 python 列表的类型在明确说明时显示为 NoneType<class 'list> ?</class> - Why does the type of my python list say NoneType when it specifically says <class 'list>? 当我期望一个列表时,为什么我没有('NoneType' object 不可迭代)? - Why do I have None ('NoneType' object is not iterable) when I expected a list? 当我有 dataframe 时,为什么 Python 会告诉我 **TypeError: unhashable type: 'list'**? - Why does Python tell me **TypeError: unhashable type: 'list'** when I have a dataframe? Python-为什么当我检查返回的对象不是NoneType时,此方法为什么返回NoneType? - Python - why does this method return NoneType when I've checked that the object I'm returning is not NoneType? 为什么空列表在返回时变成NoneType? - Why does an empty list become NoneType on return? 为什么在不是“ NoneType”的数据上出现“ NoneType”类型错误? - Why am I getting a 'NoneType' type error on data that is not a 'NoneType'? 为什么我得到NoneType指定类型 - Why I get NoneType for specified type 我的代码将运行,然后当它到达某个 function 我有 TypeError: object of type 'NoneType' has no len() - My code will run and then when it reaches a certain function I have TypeError: object of type 'NoneType' has no len() 为什么当我使用 list.extend 调用它时扩展方法不起作用? - Why is extend method not working when i call it using list.extend? 尝试在Python中扩展列表时键入错误 - Type error when trying to extend a list in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM