首页 > 其他 > 详细

Deleting elements

时间:2014-07-16 19:25:43      阅读:296      评论:0      收藏:0      [点我收藏+]

There are several ways to delete elements from a list. If you know the index of the element you want, you can use pop:

bubuko.com,布布扣                       

pop modifies the list and returns the element that was removed.

If you don’t need the removed value, you can use del operator:

bubuko.com,布布扣
If you know the element you want to remove (but not the index), you can use remove:

 bubuko.com,布布扣

The return value from remove is None.

To remove more than one element, you can use del with a slice index:

 bubuko.com,布布扣

As usual, the slice selects all elements up to, but not including, the second index.

 

 

from Thinking in Python

Deleting elements,布布扣,bubuko.com

Deleting elements

原文:http://www.cnblogs.com/ryansunyu/p/3841298.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!