Python语言基础
Python语言进阶
Python数据结构

Python List reverse()方法

搞懂Python List reverse()方法的用法
<<< Python 列表

描述

reverse() 函数用于反向列表中元素。

语法

reverse()方法语法:
list.reverse()

参数

NA。

返回值

该方法没有返回值,但是会对列表的元素进行反向排序。

实例

以下实例展示了 reverse()函数的使用方法:
list = ['wolf', 'lion', 'horse', 'pig', 'dog', 'cat']
list.reverse()
print("列表反转后: ", list)
以上实例输出结果如下:
列表反转后: ['wolf', 'lion', 'horse', 'pig', 'dog', 'cat']

Python list更多操作方法说明

Python list操作方法
list.append(obj)
在列表末尾添加新的对象
list.count(obj)
统计某个元素出现的次数
list.extend(seq)
用新列表扩展原来的列表
list.index(obj)
找出值第一个匹配项的位置
list.insert(index, obj)
将对象插入列表
list.pop([index=-1])
移除列表中的最后一个元素
list.remove(obj)
移除列表中值的第一个匹配项
list.reverse()
反向列表中元素
list.sort( key=None, reverse=False)
对原列表进行排序
list.clear()
清空列表
list.copy()
复制列表
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4