本文摘自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 while循环语句讲解与同步解析(代码示例)
如何让Python脚本成为在windows环境中运行的exe文件
Python写错了怎么删除
Python读什么
Python ide之pycharm中的快捷键总结
Python能代替shell吗
女生学Python难吗
一文通读Python自定义函数与Python函数返回值,附有详细示例
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python中关于列表list的整数操作与字符操作以及矩阵操作的实例分析