What's the difference between the list methods append() and extend()?
append: Appends object at end.
x = [1, 2, 3]
gives you: [1, 2, 3, [4, 5]]
extend: Extends list by appending elements from the iterable.
x = [1, 2, 3]
gives you: [1, 2, 3, 4, 5]
Python append() method adds an element to a list, and the extend() method concatenates the first list with another list (or another iterable). When append() method adds its argument as a single element to the end of a list, the length of the list itself will increase by one. Whereas extend() method iterates over its argument adding each element to the list, extending the list. The length of the list will increase by however many elements were in the iterable argument.
There is a simple difference between append and insert in python list, append method can be use for adding new element in the list only but by using insert we can add as well as can modify already occupied position
append: Appends object at the end.
x = ...READ MORE
Appends object at the end.
x = [1, ...READ MORE
Lists and arrays are used in Python ...READ MORE
There is a simple difference between append ...READ MORE
difference = list(set(list1) - set(list2))
xrange only stores the range params and ...READ MORE
If we use "==" means both variables ...READ MORE
exec is not an expression: a statement ...READ MORE
++ is not an operator. It is ...READ MORE
It's because any iterable can be ...READ MORE
Already have an account? Sign in.