当前位置:网站首页>Example 040: Reverse List
Example 040: Reverse List
2022-08-04 01:39:00 【Lazy laughing】
Title: Output an array in reverse order.
Program Analysis: Swap positions in sequence, or call the reverse method directly.
Code:
Method one:
lis = [1, 10, 100, 1000, 10000, 100000]for i in range(int(len(lis) / 2)):lis[i], lis[len(lis) - 1 - i] = lis[len(lis) - 1 - i], lis[i]print(lis)Method Two:
lis = [1, 10, 100, 1000, 10000, 100000]print(lis[::-1])Method three:
lis.reverse()print(lis)Results:

"""Problems encountered during study and no one answered?The editor has created a QQ group for Python learning and communication, and you can enter the officially recommended group by scanning the code below.Looking for like-minded friends to help each other, there are also good video learning tutorials and PDF e-books in the group!↓↓↓↓↓↓"""边栏推荐
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- Quickly build a website with static files
- esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)
- 在Activity中获取另一个XML文件的控件
- 【无标题】
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- 观察者模式
- 工程制图复习题
- 工程制图平面投影练习
- KunlunBase 1.0 is released!
猜你喜欢

Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)

持续投入商品研发,叮咚买菜赢在了供应链投入上

2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"

flask框架初学-06-对数据库的增删改查

nodejs+npm的安装与配置

esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)

实例040:逆序列表

哎,又跟HR在小群吵了一架!

MySQL回表指的是什么
![Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.](/img/10/87c0bedd49b5dce6fbcd28ac361145.png)
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
随机推荐
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
nodejs安装及环境配置
【OpenCV】-重映射
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
How to find the cause of Fiori Launchpad routing errors by single-step debugging
Promise 解决阻塞式同步,将异步变为同步
持续投入商品研发,叮咚买菜赢在了供应链投入上
KunlunBase 1.0 发布了!
Installation and configuration of nodejs+npm
特征值与特征向量
idea中diagram使用
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
vxe-table 从页面批量删除数据 (不动数据库里的数据)
网络带宽监控,带宽监控工具哪个好
Tanabata festival coming, VR panoramic look god assists for you
持续投入商品研发,叮咚买菜赢在了供应链投入上
Hey, I had another fight with HR in the small group!
什么是SVN(Subversion)?
OpenCV如何实现Sobel边缘检测
2022年上半年各大厂Android面试题整理及答案解析(持续更新中......)