首页 > 代码库 > Python_week5_lists
Python_week5_lists
list
list.reverse()
list.sort()
list.index(obj):obj is the object to be find out; it returns index of the found object otherwise raise an exception indicating that value does not find.
aList = [123, ‘xyz‘, ‘zara‘, ‘abc‘];print "Index for xyz : ", aList.index( ‘xyz‘ ) ; //return 1print "Index for zara : ", aList.index( ‘zara‘ ) ;//return 2
list.append(x)
list.insert(i, x):insert x after list[i].
list.pop():the last item will be removed.
list.pop(3) :delete the list[3].the argument is index.so sometimes, you may use list.pop(list.index(obj))
list.remove(sth):delete the ‘sth‘.
list.extend(an_iter):add each item from the iterable an_iter onto the list.
Difference between extend and append:
iteration
warning: we can‘t modify a list while interating over it.
settle: create another list
Python_week5_lists
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。