python_ list and Ganso
Author:Lxy
list (lists)
A list is a built-in data type of Python, and list is an ordered set of elements that can be added and removed at any time.
gets the list of elements to be obtained with a corner mark, a corner mark can use a positive angle, or you can use a negative angle, throw Indexerro when out of bounds
The data type of the elements in the list can also be different (just like in Java), or you can put another list within the list, which creates a multidimensional collection
Method of List
len (list) #获取lest长度
append () #末尾追加元素
pop () #弹出末尾元素
For example:
>>>zoo = [' Pig ', ' tiger ', ' dog ']
>>>zoo
[' Pig ', ' tiger ', ' dog ']
>>>zoo[0]
' Pig '
>>>zoo[-1]
' dog '
tuple (Ganso)
Ganso is also an ordered list, and the list is very similar, the difference is the tuple once defined can not be modified, in a sense this also improves the security of the code, the Query method and list, the use of a tuple can use a tuple.
Add "comma" when defining Ganso with 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 change, in fact the tuple does not change, the value of the internal list is changed.>>> country = (' BJ ', [' sh ', ' GD '])
>>> Country[1]
[' sh ', ' GD ']
>>> country[1][0] = ' yn '
>>> Country
(' BJ ', [' yn ', ' gd '])
>>>
from group:Java user groups
Python_ list and Ganso