python速成

list类型中所有的方法(除sort之外), 每一个方法附带一个实例:以及解释说明

append

append(self, object, /)

    Append object to the end of the list.

clear

clear(self, /)

    Remove all items from list.     从列表中删除所有项目。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data.clear()
print(list_data)

  

copy

copy(self, /)

   Return a shallow copy of the list.   返回列表的浅层副本。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data1 = list_data.copy()
print(list_data1)

  

count

count(self, value, /)

   Return number of occurrences of value.   返回值的出现次数。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
print(list_data.count(1))

 

为2的原因,Ture在计算机识别时也是1

extend

extend(self, iterable, /)

   Extend list by appending elements from the iterable.  通过添加可迭代项中的元素来扩展列表。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data1 = [(1, 2), (3, 4), (5, 6)]
list_data.extend(list_data1)
print(list_data)

index

index(self, value, start=0, stop=9223372036854775807, /)

  Return first index of value.   返回值的第一个索引。(返回脚标)

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
print(list_data.index(1))

   

insert

insert(self, index, object, /)

  Insert object before index.    在索引之前插入对象。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data.insert(2, 3)
print(list_data)

  

pop

pop(self, index=-1, /)

  Remove and return item at index (default last). 删除并返回索引处的项(默认为最后一个)。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data.pop(3)
print(list_data)

  

remove

remove(self, value, /)

  Remove first occurrence of value.  删除第一次出现的值。

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data.remove(1)
print(list_data)

  

reverse

reverse(self, /)

  Reverse *IN PLACE*.  倒置

list_data = [1, 1.2, 1+1j, "he", True, None, (), []]
list_data.reverse()
print(list_data)

  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值