1. The list can contain any data element. The elements in a single list do not need to be of the same type.
2. The append () method adds a new element to the end of the list. Only one parameter is accepted.
3. The extend () method accepts only one list as a parameter and adds each element of this parameter to the original list.
Append () usage example:
>>> Mylist = [1, 2, 0, 'abc']
>>> Mylist
[1, 2, 0, 'abc']
>>> Mylist. append (4)
>>> Mylist
[1, 2, 0, 'abc', 4]
>>> Mylist. append ('hahaha ')
>>> Mylist
[1, 2, 0, 'abc', 4, 'hahaha']
>>>
Extend () usage example:
>>> Mylist
[1, 2, 0, 'abc', 4, 'hahaha']
>>> Mylist. Extend (['lulu'])
>>> Mylist
[1, 2, 0, 'abc', 4, 'hahaha', 'lulu']
>>> Mylist. Extend ([AAA, 'lalala '])
Traceback (most recent call last ):
File "<stdin>", line 1, in <module>
Nameerror: Name 'aaa' is not defined
>>> Mylist. Extend (['20140901', 'lalala '])
>>> Mylist
[1, 2, 0, 'abc', 4, 'hahaha', 'lulu', '123', 'lalala ']
>>> Mylist. Extend ([1, 111111,222])
>>> Mylist
[1, 2, 0, 'abc', 4, 'hahaha', 'lulu', '000000', 'lalala ', 123123]
>>>
Over!