+ 1
Which code is more preferred to add item to list..?
I think using" += "to add an item to a list is easier than using " .append ".....when it does the same job why use .append
10 Answers
+ 3
There are many ways or approaches to do the same thing, many libraries and functionalities that get to the same result, but the app's performance is impacted by the approach used.
Consider ArrayList vs LinkedList in java, both are flexible and very similar lists, but ArrayList is best working from the first index to the last in line, and LinkedList is best looking at a specific index due to the algorithms on them. The append just move to the last position and add the value opening the next index, while the "+=" should move through the entire list compering values, and then adding the difference, in the end you should get the same result just not the same way.
+ 3
@Abhinav
list+=list works like list.extend(list)
list.append is for individual lists.
Anyways, if lists have the __iadd__ magic method defined, obviously they can do that.
+ 2
hii
+ 2
thank you.
+ 1
oof
You mixed up ArrayList and LinkedList.
0
hey
0
You won't like Java.
0
y so?
0
Unless you're madman who uses naked arrays, you have to use methods to add objects to containers.
0
okay