本文摘自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 输出是省略号的问题
传授 每30秒学会一个Python小技巧
Python怎么创建模块
Python pyqt4实现qq抽屉效果
Python数据采集--beautifulsoup的使用
Python实现删除时保留特定文件夹和文件的示例
如何用Python控制浏览器
Python中队列的实现方法(代码示例)
Python随机密码的生成教程
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于列表list的整数操作与字符操作以及矩阵操作的实例分析