0

About extend in py

Is there any defence between extending a list to another and adding a list to a another? A = [1,2,3,4,5] B =[0,1,96,66,52] A.extend(B) print(A) And A = [1,2,3,4,5] B =[0,1,96,66,52] A = A+B print(A(

5th May 2019, 9:00 AM
Amirabbas
Amirabbas - avatar
2 Respostas
+ 1
With extend(), B can be any kind of iterable, whereas with +, B can only be a list. This problem is solved using +=. Other differences: https://stackoverflow.com/questions/3653298/
5th May 2019, 1:24 PM
Diego
Diego - avatar
+ 1
Ok... thanks alot Diego 👍
6th May 2019, 9:02 AM
Amirabbas
Amirabbas - avatar