extend() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

extend()

Why it gives None? A=[1,2] B=[3,4] C=A.extend(B) print (C)

2nd Aug 2018, 7:52 AM
tardigrade
tardigrade - avatar
6 Answers
+ 2
extend is a function performed on a list which returns none which is stored in C. A holds [1,2,3,4]
2nd Aug 2018, 8:05 AM
JME
+ 2
Does it mean that we can't assign extended list to any value?
2nd Aug 2018, 8:08 AM
tardigrade
tardigrade - avatar
+ 2
Right, just do C = A + B
2nd Aug 2018, 8:11 AM
JME
+ 2
At least not like this with the extend method. But as Jason said: C = A + B does exactly what you intend to do.
2nd Aug 2018, 10:46 AM
HonFu
HonFu - avatar
+ 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?
25th Oct 2018, 9:47 AM
Mbrustler
Mbrustler - avatar
+ 1
yes
26th Oct 2018, 4:26 AM
tardigrade
tardigrade - avatar