求教list的remove方法
1
>>> c=['s1','s2']
>>> c
['s1', 's2']
>>> c.remove('s1')
>>> c
['s2']
2
>>> print ['s1','s2'].remove('s2')
求教一下1和2的区别在哪里,为什么我用第二种方式得到的是None? 你做的只是相当于下面这样的
1
>>> c=['s1','s2']
>>> c
['s1', 's2']
>>> c.remove('s1')
2
>>> print ['s1','s2'].remove('s2') 没明白
回复 2# bskay
Syntax
Following is the syntax for remove() method:
list.remove(obj)
Parameters
obj -- This is the object to be removed from the list.
Return Value
This method does not return any value but removes the given object from the list. thanks回复 4# HH106
列表对象的方法都是在 "原处"进行修改的! ['s1','s2'].remove('s2') 没有返回值,所以没输出。 Python 2.7.6 (default, Nov 10 2013, 19:24:24) on win32
Type "copyright", "credits" or "license()" for more information.
>>> x=['s1','s2']
>>> x
['s1', 's2']
>>> x.remove('s2')
>>> x
['s1']
>>>
页:
[1]