In Python, the list.extend(iterable)
method does not return any value—instead, it modifies the list in place and returns None
. When you do:
python
Copy code
numb.insert(6, numb.extend(letlst))
- The call
numb.extend(letlst)
adds the elements of letlst
(["cat", "dog", "hen"]
) to numb
. This expands numb
, but importantly returns None
. - You then call
numb.insert(6, None)
, effectively inserting the value None
at index 6
because that was the return value from numb.extend(letlst)
.
Hence, 'None'
shows up in your list because extend()
doesn’t produce a new list—it updates the existing list and returns None
. That None
is then inserted into your list.
How to Fix
If your goal is just to extend the list, you can separate the operations:
python
Copy code
numb.extend(letlst) # Extends the list
numb.insert(6, "hello") # Insert the string "hello" at index 6 if desired
Or if you need both operations together, do something like:
python
Copy code
# Extend first
numb.extend(letlst)
# Then insert something (like "hello") afterward
numb.insert(6, "hello")
This way, you won’t inadvertently insert None
into your list.