本文摘自php中文网,作者黄舟,侵删。
这篇文章主要介绍了Python列表list解析操作,结合实例形式分析了Python列表针对整数、字符及矩阵的解析操作实现技巧,需要的朋友可以参考下本文实例讲述了Python列表list解析操作。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | print
print "把0到8的数字依次加上五,并把结果值放在linList中"
intList = [x + 5 for x in range ( 8 )]
for ele in intList:
print ele,
print
print "从0到8的数字中挑出奇数,并把奇数进行乘方操作,结果保存在powerLIst"
powerList = [x * * 2 for x in range ( 8 ) if x % 2 ]
for pl in powerList:
print pl,
print
print "把字符串ewang转换成大写字母,并把结果保存在upperList中"
upperList = [char.upper() for char in "ewang" ]
for up in upperList:
print up,
print
print
str = 'EwAaNg'
matrixList = [(char.lower(),index) for char in str if char.isupper() for index in range ( len ( str )) if str [index].isupper() and str [index] = = char]
for mat in matrixList:
print mat,
print
|
运行结果:
以上就是Python中关于列表list的整数操作与字符操作以及矩阵操作的实例分析的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python什么时候出现的
Python如何提高运行速度
Python是一种什么类型的编程语言
anaconda多版本和环境下Python的不同配置操作方法
Python类的继承是什么?类的继承有什么样的规则?
Python如何读取txt文件
Python中单下划线和双下划线有什么区别
Python是汇编语言吗
对Python 2.7 pandas 中的read_excel详解
Python可以做app么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于列表list的整数操作与字符操作以及矩阵操作的实例分析