Python中常用列表方法分享


本文摘自php中文网,作者小云云,侵删。

本文主要和大家分享Python中常用列表方法,主要以代码的形式和大家讲解,希望能帮助到大家。

append(...) 在列表尾部添加元素
| L.append(object) -> None -- append object to end

count(...) 检查列表元素中是否存在该内容

| L.count(value) -> integer -- return number of occurrences of value

extend(...) 合并列表

| L.extend(iterable) -> None -- extend list by appending elements from the iterable

insert(...) 在某个元素前插入元素

| L.insert(index, object) -- insert object before index

pop(...) 删除某个元素 默认是最后一个 pop(0)就是删除第一个元素
| L.pop([index]) -> item -- remove and return item at index (default last).

| Raises IndexError if list is empty or index is out of range.

sort(...) 排序 要求元素类型一致,否则会出错!

| L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*

reverse(...) 逆序

| L.reverse() -- reverse *IN PLACE*

| remove(...) 删除某个值的元素
| L.remove(value) -> None -- remove first occurrence of value.
| Raises ValueError if the value is not present.

相关推荐:

Python常用列表数据结构小结

以上就是Python中常用列表方法分享的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

Python中的生成器是什么?生成器有什么用处?

Python实现高性能测试工具(二)

Python有关名字绑定的相关介绍

Python函数参数默认值的用法及注意要点

Python怎么导出eps文件

简单介绍Python编程中的字符串编码问题

iPython notebook是什么意思?

Python字符串反转

Python函数之classmethod()

Python + selenium自动化环境搭建的完整步骤

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...