Python _ list and ancestor
Python _ list and ancestor
Author: lxy
List)
A list is a built-in data type of Python. A list is an ordered set that allows you to add and delete elements at any time.
Obtain the elements in the list using the badge. You can use the badge or the negative badge. If the badge is out of the range, IndexErro is thrown.
The Data Types of elements in the list can be different (just like Java), or another list can be placed in the list, which forms a multi-dimensional set.
List Method
Len (list) # obtain the lest Length
Append () # append Element
Pop () # elements at the end of the pop-up
For example:
>>> Zoo = ['pig', 'tiger ', 'Dog']
>>> Zoo
['Pig', 'tiger ', 'Dog']
>>> Zoo [0]
'Pig'
>>> Zoo [-1]
'Dog'
Tuple)
Yuanzu is also an ordered list, which is very similar to list. The difference is that once tuple is defined, it cannot be modified. In a sense, this improves the code security. The query method is the same as list, tuple is used when tuple is used.
Add a comma when defining the ancestor of only one element to avoid ambiguity with mathematical operations.
Variable tuple
When a list is placed inside the ancestor, the value of the list in the ancestor can be changed. In fact, tuple has not changed, change the value of the internal list >>> country = ('bj ', ['sh', 'gd'])
>>> Country [1]
['Sh', 'gd ']
>>> Country [1] [0] = 'yny'
>>> Country
('Bj ', ['yn', 'gd '])
>>>
From group: Java User Group