List
A list is an ordered collection in which the element data types can be different. You can add and remove elements at any time.
1. Define
>>> list = []
>>> list
[]
>>>
2. Add/Remove Append element to end of list
>>> list.append (1)
>>> list
[1]
>>> list.append (' a ')
>>> list
[1, ' a ']
>>>
Inserts an element into a specified location
>>> List.insert (1, one)
>>> list
[1, one, ' a ']
>>>
Delete the element at the end of the list
>>> list.pop ()
' a '
>>> list
[1, one]
>>> l
Deletes the element at the specified location
>>> list.pop (0)
1
>>> list
[one]
>>>
To replace an element with another element
>>> list
[one]
>>> list[0]=111
>>> list
[+]
>>>
List can contain another list
>>> list
[a]
>>> list2=[' a ']
>>> list2
[' a ']
>>> List2.append (list)
>>> list2
[' A ', []]
>>>
3. Commonly used functions to calculate the length of the list
>>> len (list)
1
>>> len (list2)
2
>>>
tuple
Tuple: Tuple, also a sequence table. Tuple can not be modified once initialized. If an element in tuple is a list, the list can be changed.
1. Define
Define an empty tuple
>>> t= ()
>>> T
()
>>>
define a tuple > with only one element
>> t= (1) #错误, this time () represents the parentheses in the mathematical formula
>>> T
1
>>> t= (1,)
>>> t
(1, )
>>>
2. Commonly used functions to calculate the length of tuple
>>> len (t)
1
>>>