当前位置:网站首页>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!↓↓↓↓↓↓"""
边栏推荐
猜你喜欢
随机推荐
Installation and configuration of nodejs+npm
Apache DolphinScheduler actual combat task scheduling platform - a new generation of distributed workflow
ASP.NET 获取数据库的数据并写入到excel表格中
KunlunBase 1.0 is released!
typescript58 - generic classes
Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar
HBuilderX的下载安装和创建/运行项目
观察者模式
Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
typescript51 - basic use of generics
【正则表达式】笔记
The 600MHz band is here, will it be the new golden band?
可变字符串
LDO investigation
实例038:矩阵对角线之和
字符串变形
LDO investigation
Array_Sliding window | leecode brushing notes
【OpenCV】-重映射
内网穿透-应用