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.
Thanks!
extend
, like many other list operations, operates in-place and returns None. ListA
is modified with the extra elements.
You did not define ListC as a list type.
As you know, list() is a function; which generates a list type.
list.extend does not. 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.
It is good that you noticed the difference between + and list.extend(). Keep it up and good luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.