Python: extend() Append Elements of a List to a List
By Güngör Budak
- One minute read - 57 wordsWhen you append a list to a list by using append() method, you’ll see your list is going to be appended as a list:
1>>>l=["a"]
2>>>l2=["a", "b"]
3>>>l.append(l2)
4>>>l
5['a', ['a', 'b']]
If you want to append elements of the list directly without creating nested lists, use extend() method:
1>>>l=["a"]
2>>>l2=["a", "b"]
3>>>l.extend(l2)
4>>>l
5['a', 'a', 'b']