The list is implemented in the form of a class. The "create" list actually instantiates a class. Therefore, the list can be operated in multiple ways. 1. the list can contain any data type elements. 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" ", Line 1, in
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!