codecamp

Python List remove()方法

Python List remove()方法


描述

remove() 函数用于移除列表中某个值的第一个匹配项。

语法

remove()方法语法:

list.remove(obj)

参数

  • obj -- 列表中要移除的对象。

返回值

该方法没有返回值但是会移除列表中的某个值的第一个匹配项。

实例

以下实例展示了 remove()函数的使用方法:

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 'xyz'];

aList.remove('xyz');
print "List : ", aList;
aList.remove('abc');
print "List : ", aList;

以上实例输出结果如下:

List :  [123, 'zara', 'abc', 'xyz']
List :  [123, 'zara', 'xyz']
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }