python 反转列表_如何反转Python列表元素?

python 反转列表

python 反转列表

The list is a popular structure or composite data type used in Python programming language. One of the most used functions or operations with a list is reversing the list items. Reversing the list items will make the last item as the first item vice versa. In order to reverse a list in Python, there are different functions and methods like reverse() function, slicing, reversed() function with the loop.

该列表是Python编程语言中常用的结构或复合数据类型。 列表最常用的功能或操作之一是反转列表项。 反转列表项将使最后一项成为第一项,反之亦然。 为了在Python中反转列表,循环中有不同的函数和方法,例如reverse()函数,切片,reversed()函数。

reverse()列表函数 (reverse() Function Of List)

List data type provides the reverse() function which is the most practical way to reverse items in a list. reverse() function does not need any parameter as it will use the list object items and put the reversed items in the current list too. In the following example, we will use the numbers as list items in order to depict the reversing operation. The items in the list named numbers will start from 1 to 9 .

列表数据类型提供了reverse()函数,这是反转列表中项目的最实用方法。 reverse()函数不需要任何参数,因为它将使用列表对象项并将颠倒的项也放入当前列表中。 在下面的示例中,我们将数字用作列表项,以描述反转操作。 列表中名为numbers的项目将从1到9开始。

numbers=[1,2,3,4,5,6,7,8,9]

print("Normal List",numbers)
Normal List [1, 2, 3, 4, 5, 6, 7, 8, 9]

numbers.reverse()

print("Reversed List",numbers)
Reversed List [9, 8, 7, 6, 5, 4, 3, 2, 1]

numbers.reverse()

print("Normal List Again",numbers)
Normal List Again [1, 2, 3, 4, 5, 6, 7, 8, 9]
reverse() Function Of List 
reverse() Function Of List
reverse()列表函数

We can see that when we call the

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值