当前位置:网站首页>实例040:逆序列表
实例040:逆序列表
2022-08-04 01:35:00 【懒笑翻】
题目:将一个数组逆序输出。
程序分析:依次交换位置,或者直接调用reverse方法。
代码:
方法一:
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)
方法二:
lis = [1, 10, 100, 1000, 10000, 100000]
print(lis[::-1])
方法三:
lis.reverse()
print(lis)
结果:
"""
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,扫码下方官方推荐的群即可进入哦
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!↓↓↓↓↓↓
"""
边栏推荐
- 字符串变形
- jmeter跨平台运行csv等文件
- 网络带宽监控,带宽监控工具哪个好
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- 无代码7月热讯 | 微软首推数字联络中心平台;全球黑客马拉松...
- Thinkphp commonly used techniques
- C语言:学生管理系统(链表版)
- Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
猜你喜欢
nodejs切换版本使用(不需要卸载重装)
持续投入商品研发,叮咚买菜赢在了供应链投入上
typescript56 - generic interface
《Greenplum构建实时数据仓库实践》简介
How to find the cause of Fiori Launchpad routing errors by single-step debugging
一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包
LeetCode third topic (the Longest Substring Without Repeating Characters) trilogy # 3: two optimization
114. How to find the cause of Fiori Launchpad routing error by single-step debugging
DDTL:远距离的域迁移学习
Web3 security risks daunting?How should we respond?
随机推荐
Jmeter cross-platform operation CSV files
持续投入商品研发,叮咚买菜赢在了供应链投入上
typescript51-泛型的基本使用
OpenCV如何实现Sobel边缘检测
nodejs+express realizes the access to the database mysql and displays the data on the page
Is there any jdbc link to Youxuan database documentation and examples?
IDEA02:配置SQL Server2019数据库
typescript52-简化泛型函数调用
flask框架初学-06-对数据库的增删改查
【无标题】
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
GNSS[0]- Topic
Slipper —— 虚点,最短路
字符串的排列
VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience
nodejs+npm的安装与配置
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
js中常用的几种遍历处理数据的方法梳理
Promise 解决阻塞式同步,将异步变为同步