Here, we are implementing a python program for various list operations, following operations are being performed in the list,

在这里,我们正在为各种列表操作实现python程序,正在列表中执行以下操作,

  1. Declaring an integer list

    声明一个整数列表

  2. Printing the complete list

    打印完整列表

  3. Printing the first element of the list

    打印列表的第一个元素

  4. Printing ith element of the list

    打印列表的第i个元素

  5. Printing elements within the given indexes

    在给定索引中打印元素

  6. Printing a specific element using negative indexing

    使用负索引打印特定元素

  7. Appending an element to the list

    将元素追加到列表

  8. Finding the index of a specific element in the list

    在列表中查找特定元素的索引

  9. Sorting the list elements

    排序列表元素

  10. Popping an element from the list

    从列表中弹出一个元素

  11. Removing specified element from the list

    从列表中删除指定的元素

  12. Inserting an element at specified index

    在指定索引处插入元素

  13. Extending the list i.e. insert set of element (list) in the list

    扩展列表,即在列表中插入一组元素(列表)

  14. Reversing list elements

    反转列表元素

用于各种列表操作的Python代码 (Python code for various list operation)

# Python code for various list operation
# declaring a list of integers
iList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
# List slicing operations
# printing the complete list
print('iList: ',iList)
# printing first element
print('first element: ',iList[0])
# printing fourth element
print('fourth element: ',iList[3])
# printing list elements from 0th index to 4th index
print('iList elements from 0 to 4 index:',iList[0: 5])
# printing list -7th or 3rd element from the list
print('3rd or -7th element:',iList[-7])
# appending an element to the list
iList.append(111)
print('iList after append():',iList)
# finding index of a specified element
print('index of \'80\': ',iList.index(80))
# sorting the elements of iLIst
iList.sort()
print('after sorting: ', iList);
# popping an element
print('Popped elements is: ',iList.pop())
print('after pop(): ', iList);
# removing specified element
iList.remove(80)
print('after removing \'80\': ',iList)
# inserting an element at specified index
# inserting 100 at 2nd index
iList.insert(2, 100)
print('after insert: ', iList)
# counting occurances of a specified element
print('number of occurences of \'100\': ', iList.count(100))
# extending elements i.e. inserting a list to the list
iList.extend([11, 22, 33])
print('after extending:', iList)
#reversing the list
iList.reverse()
print('after reversing:', iList)

Output

输出量

iList:  [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
first element:  10
fourth element:  40
iList elements from 0 to 4 index: [10, 20, 30, 40, 50]
3rd or -7th element: 40
iList after append(): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111]
index of '80':  7
after sorting:  [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111]
Popped elements is:  111
after pop():  [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
after removing '80':  [10, 20, 30, 40, 50, 60, 70, 90, 100]
after insert:  [10, 20, 100, 30, 40, 50, 60, 70, 90, 100]
number of occurences of '100':  2
after extending: [10, 20, 100, 30, 40, 50, 60, 70, 90, 100, 11, 22, 33]
after reversing: [33, 22, 11, 100, 90, 70, 60, 50, 40, 30, 100, 20, 10]

翻译自: https://www.includehelp.com/python/program-for-various-list-operations.aspx

适用于各种列表操作的Python程序相关推荐

  1. 电源变换适用于非独立源码_适用于非None测试的Python程序

    电源变换适用于非独立源码 As we have discussed in the previous post (Python None keyword), that "None" ...

  2. python程序怎么保存到u盘_Python 骚操作,自动拷贝U盘

    阅读文本大概需要 6 分钟. Python 这门语言有非常多有趣的内容,比如给微信好友自动发消息.查看微信好友撤回的消息.通过微信控制电脑等等.在我公众号上也分享过很多有趣的程序,近期我会去搜集一些骚 ...

  3. Python 程序员最常犯的十个错误

    常见错误1:错误地将表达式作为函数的默认参数 在Python中,我们可以为函数的某个参数设置默认值,使该参数成为可选参数.虽然这是一个很好的语言特性,但是当默认值是可变类型时,也会导致一些令人困惑的情 ...

  4. Python 程序员最常犯的十个错误,作为小白的你是不是也经常犯?

    常见错误1:错误地将表达式作为函数的默认参数 在Python中,我们可以为函数的某个参数设置默认值,使该参数成为可选参数.虽然这是一个很好的语言特性,但是当默认值是可变类型时,也会导致一些令人困惑的情 ...

  5. Python程序员常犯的十个错误

    不管是在学习还是工作过程中,人都会犯错.虽然Python的语法简单.灵活,但也一样存在一些不小的坑,一不小心,不管是初学者还是资深Python程序员都有可能会栽跟头. 常见错误1:错误地将表达式作为函 ...

  6. python代码实例-python程序实例

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. github.comteamssixdouluo-download.gi ...

  7. python列表操作计算列表长度并输出_Python成为专业人士笔记–List列表

    专业人士笔记"系列目录:创帆云:Python成为专业人士笔记--强烈建议收藏!每日持续更新!​zhuanlan.zhihu.com Python列表是Python程序中广泛使用的一种通用数据 ...

  8. python编程实例详解-Python编程之列表操作实例详解【创建、使用、更新、删除】...

    这篇文章主要介绍了Python编程之列表操作,结合实例形式分析了Python列表的创建.使用.更新.删除等实现方法与相关操作技巧,需要的朋友可以参考下 #coding=utf8 ''''' 列表类型也 ...

  9. python列表操作函数大全_Python列表操作函数

    列表可以进行多个数据的存储,同时python中的列表设计非常到位,它可以实现内容动态扩充,可以进行后期数据的删除,这些就需要通过Python提供的列表操作函数来实现了. 对于Python语言而言,开发 ...

最新文章

  1. [译]Godot系列教程一 - 场景与节点
  2. iOS最好用的引导页
  3. 【控制】《多智能体系统的动力学分析与设计》徐光辉老师-目录
  4. php 7 pcntl扩展,PHP_Linux系统中为php添加pcntl扩展,pcntl扩展可以支持php的多线程 - phpStudy...
  5. 太吾绘卷第一世攻略_耽美推文-BL-仿佛在攻略一只河豚
  6. 用hyperledger cello H3C分支创建单机模式区块链系统
  7. 这才是真正适合小白的教程:Python有什么用?数据化运营怎么做?
  8. 道路上下行是什么意思_了解道路禁止符号 春节压岁钱少填罚款
  9. UA MATH523A 实分析3 积分理论例题 Fubini定理计算简单一元定积分的一个例题
  10. 使用MATLAB Mapping工具箱创建和编辑地图
  11. 机器人国际会议与期刊列表
  12. 2021年全球手工具收入大约16510百万美元,预计2028年达到18370百万美元
  13. 凯斯西储大学计算机科学排名,凯斯西储大学排名计算机工程,超牛干货分解
  14. spssfisher判别分析步骤_spss进行判别分析步骤_spss判别分析结果解释_spss判别分析案例详解...
  15. Windows 7 Build 7068 下载泄露
  16. 升压电路(Boost)的设计原理、参数计算及MATLAB仿真
  17. 微信播放在服务器视频无法播放音乐,【bug解决】ios微信浏览器中背景音乐无法播放...
  18. 登录SSH/winSCP一直显示密码错误
  19. 响应式扩展_响应式和无限扩展的JS动画
  20. 键盘的Win键失效或者被锁的解决办法

热门文章

  1. mysql分表 查询 优化_MySQL性能管理及架构(查询优化、分库分表)一遍文章搞定...
  2. TensorFlow构建二维数据拟合模型(3)
  3. 和push的区别_还没有理解let 和 const的用法和区别吗,几百字让你立马搞懂
  4. android studio 跨进程,Android IPC机制(三)在Android Studio中使用AIDL实现跨进程方法调用...
  5. linux x86 关机 过程,linux在x86上的中断处理过程(详细)
  6. CENTOS5下VSFTPD的设置
  7. 这一年多来,阿里Blink测试体系如何从0走向成熟?
  8. [转]资本经营董事长班告诉你:不只企业有商业模式,个人商业价值更重要
  9. svn: Can't convert string from 'UTF-8' to native
  10. R语言:ggplot2精细化绘图——以实用商业化图表绘图为例(转)