当前位置:网站首页>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

lombok注解@RequiredArgsConstructor的使用

DDTL:远距离的域迁移学习

安全至上:落地DevSecOps最佳实践你不得不知道的工具

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

nodejs+express realizes the access to the database mysql and displays the data on the page

Quickly build a website with static files

一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包

JS 保姆级贴心,从零教你手写实现一个防抖debounce方法

HBuilderX的下载安装和创建/运行项目
随机推荐
TensoFlow学习记录(二):基础操作
LDO investigation
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
哎,又跟HR在小群吵了一架!
js中常用的几种遍历处理数据的方法梳理
持续投入商品研发,叮咚买菜赢在了供应链投入上
html select标签赋值数据库查询结果
splice随机添加和删除的写法
FeatureNotFound( bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
Web APIs BOM- 操作浏览器:swiper 插件
C 学生管理系统_添加学生
ThreadLocal
nodejs安装及环境配置
【虚拟化生态平台】虚拟化平台搭建
Use nodejs switch version (no need to uninstall and reinstall)
Summary of GNSS Articles
GNSS文章汇总
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
持续投入商品研发,叮咚买菜赢在了供应链投入上
VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience