python——列表


列表(list):


class list(object):(list类中提供的方法)
"""
list() -> new empty list
list(iterable) -> new list initialized from iterable's items
"""
1、def append(self, p_object): # real signature unknown; restored from __doc__(追加)(对象。。方法。。:def对象调用append方法)
""" L.append(object) -> None -- append object to end """
pass

2、def clear(self): # real signature unknown; restored from __doc__
""" L.clear() -> None -- remove all items from L """
pass

3、def copy(self): # real signature unknown; restored from __doc__
""" L.copy() -> list -- a shallow copy of L """
return []

4、def count(self, value): # real signature unknown; restored from __doc__
""" L.count(value) -> integer -- return number of occurrences of value """
return 0

5、def extend(self, iterable): # real signature unknown; restored from __doc__
""" L.extend(iterable) -> None -- extend list by appending elements from the iterable """
pass

6、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.
"""
return 0

6、def insert(self, index, p_object): # real signature unknown; restored from __doc__
""" L.insert(index, object) -- insert object before index """
pass

7、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.
"""
pass

8、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.
"""
pass

9、def reverse(self): # real signature unknown; restored from __doc__ (将当前的列表进行反转)
""" L.reverse() -- reverse *IN PLACE* """
pass

10、def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__ (列表的排序)
""" L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
pass



补充:字符串创建不可修改
列表是有序的,可以被修改


shudian = ["李强","李程瑞","项羽茂","赵玉伟"]
modian = ["赵玉伟","李强",]

all = []
for name in shudian :
if name in modian:
all.append(name)
print(all)
#第一个列表和第二个列表做了一个关系运算,求他两的共同部分

猜你喜欢

转载自www.cnblogs.com/ydp616938947/p/8948137.html
今日推荐