>>>list=[‘a‘,1,‘1‘] >>> dir(list) [‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__iadd__‘, ‘__imul__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__reversed__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘append‘, ‘clear‘, ‘copy‘, ‘count‘, ‘extend‘, ‘index‘, ‘insert‘, ‘pop‘, ‘remove‘, ‘reverse‘, ‘sort‘] ‘append‘, ‘clear‘, ‘copy‘, ‘count‘, ‘extend‘, ‘index‘, ‘insert‘, ‘pop‘, ‘remove‘, ‘reverse‘, ‘sort‘] “追加”、“清除”、“复制”、“计数”、“扩展”、“索引”、“插入”、“弹出”、“删除”、“反向”、“排序”。 append(self, p_object): >>> list=[1] >>> list.append(2) >>> list [1, 2] >>> clear(self): >>> list=[‘a‘,‘b‘] >>> list.clear() >>> list [] >>> copy(self): >>> list=[1] >>> list1=list.copy() >>> list1 [1] >>> count(self, value): >>> list=[1,2,3,4,5,1] >>> list.count(1) 2 >>> extend(self, iterable): >>> list=[1,2,3] >>> list.extend({1:2}) >>> list [1, 2, 3, 1] >>> index(self, value, start=None, stop=None): >>> list=[1,2,3,2] >>> list.index(2) 1 >>> 没有该元素则报错 insert(self, index, p_object): >>> list=[1,2,3] >>> list.insert(3,5) >>> list [1, 2, 3, 5] >>> pop(self, index=None): >>> list=[1,2,3] >>> list.pop(0) 1 >>> list [2,3] >>> list=[1,2,3] >>> list.pop() 3 >>> list [1, 2] remove(self, value): >>> list=[1,2,3] >>> list.remove(1) >>> list [2, 3] >>> reverse(self): >>> list=[1,3,2,3] >>> list.reverse() >>> list [3, 2, 3, 1] >>> sort(self, key=None, reverse=False): >>> list=[1,3,2,3] >>> list.sort() >>> list [1, 2, 3, 3] >>>
t=(1,2) print(type(t)) print(dir(t)) 运行结果: <class ‘tuple‘> [‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__getnewargs__‘, ‘__gt__‘, ‘__hash__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘count‘, ‘index‘] count(self, value): t=(1,4,4,2,3,4,3,5) print(t.count(3)) 运行结果: 2 index(self, value, start=None, stop=None): t=(1,4,4,2,3,4,3,5) print(t.index(3)) 运行结果: 4
时间: 2024-10-11 05:06:03