amandaysu 发表于 2015-01-12 15:18

求教list的remove方法


1
>>> c=['s1','s2']
>>> c
['s1', 's2']
>>> c.remove('s1')
>>> c
['s2']

2
>>> print ['s1','s2'].remove('s2')

求教一下1和2的区别在哪里,为什么我用第二种方式得到的是None?

bskay 发表于 2015-01-12 15:25

你做的只是相当于下面这样的



1
>>> c=['s1','s2']
>>> c
['s1', 's2']
>>> c.remove('s1')

2
>>> print ['s1','s2'].remove('s2')

amandaysu 发表于 2015-01-12 16:00

没明白
回复 2# bskay


   

HH106 发表于 2015-01-12 16:07

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.

amandaysu 发表于 2015-01-12 16:32

thanks回复 4# HH106


   

reyleon 发表于 2015-01-12 16:38

列表对象的方法都是在 "原处"进行修改的!

szerr 发表于 2015-01-17 21:17

['s1','s2'].remove('s2') 没有返回值,所以没输出。

jixuuse 发表于 2015-01-19 10:20

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]
查看完整版本: 求教list的remove方法