+ 3
extend()
Why it gives None? A=[1,2] B=[3,4] C=A.extend(B) print (C)
6 Respuestas
+ 2
extend is a function performed on a list which returns none which is stored in C. A holds [1,2,3,4]
+ 2
Does it mean that we can't assign extended list to any value?
+ 2
Right, just do C = A + B
+ 2
At least not like this with the extend method. But as Jason said: C = A + B does exactly what you intend to do.
+ 2
you can do this if you want extend
a = [1,2,3,4]
b = a[:]
b.extend([5,6])
print(b)
output:
[1,2,3,4,5,6]
may i ask if you had this in a chellenge?
+ 1
yes