python3列表方法,元组方法

>>>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']
“追加”、“清除”、“复制”、“计数”、“扩展”、“索引”、“插入”、“弹出”、“删除”、“反向”、“排序”。

>>> [1,2,3,4,5][0:2]
[1, 2]
>>>

>>> [1,2,3].__len__()
3
>>>
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

 

转载于:https://www.cnblogs.com/wmxuan/p/7496894.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值