标签:
1. 获取列表中的某个值
描述:获取下标所对应的值
语法:
print(li[0]) #[下标地址]
样例:
li = list([‘a‘,‘b‘,‘c‘]) val=(li[0]) #获取下标所对应的值 print(val) a #显示结果
2. append
描述:追加对象到列表中
语法:
def append(self, p_object): # real signature unknown; restored from __doc__ """ L.append(object) -> None -- append object to end """ pass
样例:
li = list([‘a‘,‘b‘,‘c‘]) li.append(‘d‘) #追加d到列表中 print(li) [‘a‘, ‘b‘, ‘c‘, ‘d‘] #显示结果
3. insert
描述:插入对象到列表中
语法:
def insert(self, index, p_object): # real signature unknown; restored from __doc__ """ L.insert(index, object) -- insert object before index """ pass
样例:
list = [1,2,3,4] list.insert(4,‘a‘) #第4个索引后插入a print(list) [1, 2, 3, 4, ‘a‘] #显示结果
4. pop
描述:删除队列中最后一个对象
语法:
def pop(self, index=None): # real signature unknown; restored from __doc__ """ L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. """ pass
样例:
list = [1,2,3,4] list.pop() #默认删除队列中最后一个对象 print(list) [1, 2, 3] #显示结果
5. remove
描述:删除队列中指定的对象
语法:
def remove(self, value): # real signature unknown; restored from __doc__ """ L.remove(value) -> None -- remove first occurrence of value. Raises ValueError if the value is not present. """ pass
样例:
list = [1,2,3,4] list.remove(3) #删除队列中的3 print(list) [1, 2, 4] #显示结果
6. sort
描述:队列排序
语法:
def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__ """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """ pass
样例:
list = [1,2,44,22,3,4] list.sort() #顺序排序显示 print(list) [1, 2, 3, 4, 22, 44] #显示结果
7. reverse
描述:队列反转
语法:
def reverse(self): # real signature unknown; restored from __doc__ """ L.reverse() -- reverse *IN PLACE* """ pass
样例:
list = [1,2,3,4] list.reverse() #队列反转 print(list) [4, 3, 2, 1] #显示结果
8. index
描述:返回队列中值所对应的下标值,仅限第一匹配
语法:
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ """ L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. """ return 0
样例:
list = [11,2,33,3,4,11,5,33] print(list.index(11)) #查找队列中值为11的对象 0 #显示结果,返回11所在的下标值
9. count
描述:计算队列中对象的个数
语法:
def count(self, value): # real signature unknown; restored from __doc__ """ L.count(value) -> integer -- return number of occurrences of value """ return 0
样例:
list = [11,2,33,3,4,11,5,33] print(list.count(33)) #查找对象为33的个数,匹配所有对象 2 #显示结果
10. extend
描述:对列表进行扩展,可添加其他列表或者元组
语法:
def extend(self, iterable): # real signature unknown; restored from __doc__ """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """ pass
样例:
li = list([1,2,3]) li.extend([11,22, ]) #扩展添加队列到列表中 print(li) [1, 2, 3, 11, 22] #显示结果 li = list([1,2,3]) li.extend((11,22, )) #扩展添加元组到列表中 print(li) [1, 2, 3, 11, 22] #显示结果
11. clear
描述:清楚列表数据
语法:
def clear(self): # real signature unknown; restored from __doc__ """ L.clear() -> None -- remove all items from L """ pass
样例:
li = list([1,2,3]) li.clear() #清楚列表中内容 print(li) [] #显示结果
标签:
原文地址:http://www.cnblogs.com/xujianghua/p/5237999.html