码迷,mamicode.com
首页 > 其他好文 > 详细

list方法

时间:2014-08-10 01:38:29      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   strong   文件   for   art   

查看list的方法

使用dir函数查看list都有哪些命令可以使用

>>>dir(list)
[‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__delslice__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__getslice__‘, ‘__gt__‘, ‘__hash__‘, ‘__iadd__‘, ‘__imul__‘, ‘__init__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__reversed__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__setslice__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘append‘, ‘count‘, ‘extend‘, ‘index‘, ‘insert‘, ‘pop‘, ‘remove‘, ‘reverse‘, ‘sort‘]

list方法

append

>>> list.append.__doc__
‘L.append(object) -- append object to end‘

正如doc文件描述的append函数是用于附加对象到列表的末尾。

count

>>> list.count.__doc__
‘L.count(value) -> integer -- return number of occurrences of value‘

返回目标值出现的次数。

extend

 

>>> list.extend.__doc__
‘L.extend(iterable) -- extend list by appending elements from the iterable‘

 

附加元素到列表的末尾,从而来扩展列表。

index

 

 

>>> list.index.__doc__
‘L.index(value, [start, [stop]]) -> integer -- return first index of value.\nRaises ValueError if the value is not present.‘

返回目标值第一次出现位置,如果不存在则抛出错误。可以设置查找的开始和结束位置。

insert

>>> list.insert.__doc__
‘L.insert(index, object) -- insert object before index‘

在指定位置插入对象

pop

>>> list.pop.__doc__
‘L.pop([index]) -> item -- remove and return item at index (default last).\nRaises IndexError if list is empty or index is out of range.‘

remove

>>> list.remove.__doc__
‘L.remove(value) -- remove first occurrence of value.\nRaises ValueError if the value is not present.‘

 

list方法,布布扣,bubuko.com

list方法

标签:style   blog   color   使用   strong   文件   for   art   

原文地址:http://www.cnblogs.com/codeforever/p/3902262.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!