Python list method(1)

貢獻者:知乎:三生万物【标签:老朽意识】 類別:代码 時間:2020-06-26 13:16:34 收藏數:14 評分:0
返回上页 舉報此文章
请选择举报理由:




收藏到我的文章 改錯字
> my_list = ["one","two"]
> my_list.append("three")#["one","two","three"]
Add an item to the end of the list. Equivalent to a[len(a):] = [my_list].
> my_list.remove("two")#["one","three"]
Remove the first item from the list whose value is equal to "twp".
> my_list.extend([1,3])#["one","three",1,3]
Extend the list by appending all the items from the [1,3](iterable). Equivalent to a[len(a):] =
[1,3]
> my_list.pop(2)#["one","three",3]
Remove the item at the given position in the list, and return it.
If no index is specified, my_list.pop() removes and returns the last item in the list.
> my_list.clear()#[]
Remove all items from the list. Equivalent to del my_list[:].
> my_list.insert(0, "haha")#["haha"]
Insert an item at a given position. The first argument is the index of the
element before which to insert, so a.insert(0, x) inserts at the front of the list,
and a.insert(len(a), x) is equivalent to a.append(x).
It raises a ValueError if there is no such item.
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章熱度:
文章難度:
文章質量:
說明:系統根據文章的熱度、難度、質量自動認證,已認證的文章將參與打字排名!

本文打字排名TOP20

登录后可见