Python - List
时间:2010-08-19 来源:AllenW
1. Difinition
ListTest=["Value1","Value2","Vaule3"]
Note:
1)It is included by []
2)Divied by comma
2.Usage
>>> ListTest
['Value1', 'Value2', 'Value3']
>>> ListTest[0]
'Value1'
>>> ListTest[2]
'Value3'
Note:The ordinal number is increased from 0 to n-1
>>> ListTest[-1]
'Value3'
>>> ListTest[-3]
'Value1'
Note:The ordinal number is decreased from -1 to -n
3. Basic Operation
1)append
>>> ListTest.append("Value4")
>>> ListTest
['Value1', 'Value2', 'Value3', 'Value4']
2)insert
>>> ListTest.insert(2,"two")
>>> ListTest
['Value1', 'Value2', 'two', 'Value3', 'Value4']
>>> ListTest[2]
'two'
3)extend
>>> ListTest2=['Value21','Value22']
>>> ListTest2
['Value21', 'Value22']
>>> ListTest.extend(ListTest2)
>>> ListTest
['Value1', 'Value2', 'two', 'Value3', 'Value4', 'Value21', 'Value22']
相关阅读 更多 +