When I use **extend() **function to combine two lists, it returns **None**. How can I combine lists?

>>> a=[1,2,3]

>>> b=[4,5,6]

>>> f=a.extend(b)

>>> f

0 votes

extend() is an in-place function, that's why f is assigned None. The list 'a' will be extended by your code. If you want to assign the extended list to 'f', you can do one of the followings:

>>> a=[1,2,3]

>>> b=[4,5,6]

>>> f=a.extend(b)

>>> a

[1, 2, 3, 4, 5, 6]>>> f=a

>>> f

[1, 2, 3, 4, 5, 6]

>>> import numpy as np>>> f1=list(np.append(a,b))

>>> f1

[1, 2, 3, 4, 5, 6, 4, 5, 6]

>>>