list内置方法
append(self, object)
用途:在list的末尾添加一个object。
返回值:返回一个添加object的list。
object表示被添加目标(可以是任意类型)
例:
test = [‘python’]
test.append(3)
test
[‘python’, 3] #输出结果
test.append([1, 2]) #添加一个列表
test
[‘python’, 3, [1, 2]] #输出结果
test.append((5, 4,)) #添加一个元组
test
[‘python’, 3, [1, 2], (4, 5)] #输出结果
test.append(2.7) #添加一个小数
test
[‘python’, 3, [1, 2], (4, 5), 2.7]
clear(self)
用途:将list清空。
返回值:返回一个空的list
例:
test = [“python”]
test
[] #输出结果,一个空的列表
copy(self)
用途:复制一份列表。
返回值:返回列表的一个副本(修改副本不会改变原有的列表)。
例:
test = [“python”]
testCopy = test.copy()
testCopy
[“python”] #输出结果