1.创建列表
name_list = [1,2,3,] 或 name_list = list([1,2,3])
2.列表的基本操作
class list(object): #列表的类
def append(self, p_object): # real signature unknown; restored from __doc__ #追加:将对象附加到列表结尾
""" L.append(object) -> None -- append object to end """
name_list = [1,2,3,]
print(name_list)
name_list.append(11) #添加的对象可以是一个列表、元组、单个元素
print(name_list)
def clear(self): # real signature unknown; restored from __doc__ #清空列表
""" L.clear() -> None -- remove all items from L """
name_list = [1,2,3,]
print(name_list)
name_list.clear()
print(name_list)
def copy(self): # real signature unknown; restored from __doc__ #复制:浅的复制
""" L.copy() -> list -- a shallow copy of L """
def count(self, value): # real signature unknown; restored from __doc__ #计数:计算列表中元素出现的次数,并返回值
""" L.count(value) -> integer -- return number of occurrences of value """
def extend(self, iterable): # real signature unknown; restored from __doc__ #扩展列表:把对象添加到列表,对象可以是元素、元组、列表
""" L.extend(iterable) -> None -- extend list by appending elements from the iterable ""
def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__ #索引:查找元素的位置,并返回一个值
"""
L.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
"""
def insert(self, index, p_object): # real signature unknown; restored from __doc__ #插入:在索引值之前插入对象
""" L.insert(index, object) -- insert object before index """
def pop(self, index=None): # real signature unknown; restored from __doc__ #删除对象,并返回一个索引值,默认是列表最后一个
"""
L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
"""
def remove(self, value): # real signature unknown; restored from __doc__ #删除:删除第一次值出现的对象
"""
L.remove(value) -> None -- remove first occurrence of value.
Raises ValueError if the value is not present.
"""
def reverse(self): # real signature unknown; restored from __doc__ #反转
""" L.reverse() -- reverse *IN PLACE* """
def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__ #排序
""" L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
pyhton基础学习《列表的常用操作》