易截截图软件、单文件、免安装、纯绿色、仅160KB

Python入门的36个例子 之 19

源代码下载:下载地址在这里
# 022
listNum1 = [1, 3]
listNum2 = [2, 4]
listStr1 = ['a', 'c']
listStr2 = ['b', 'd']
# 列表的合并
list1 = listNum1 + listStr1
for ele in list1:
print ele
print '\n'
# 判断列表中是否包含某元素
print 'b' in list1
print 1 in list1
# 删除某个元素
for ele in list1:
print ele
del list1[1]
for ele in list1:
print ele
print '\n'
# 对列表进行排序
list1 = listNum1 + listNum2 + listStr1 + listStr2
for ele in list1:
print ele
print '\n'
list1.sort()
for ele in list1:
print ele
print '\n'
# 对列表进行倒排序
list1 = listNum1 + listNum2 + listStr1 + listStr2
for ele in list1:
print ele
print '\n'
list1.sort(reverse = True)
for ele in list1:
print ele
print '\n'
# 对列表进行逆序
list1 = listNum1 + listNum2 + listStr1 + listStr2
for ele in list1:
print ele
print '\n'
list1.reverse()
for ele in list1:
print ele
print '\n'
# 删除列表中连续的一部分
list2 = listNum1 + listNum2 + listStr1 + listStr2
list1 = list2
list1.sort()
for ele in list1:
print ele
print '\n'
del list1[0:2]
for ele in list1:
print ele
print '\n'
# Python中列表比较的是值而不是引用
list3 = [1, 3, 'a', 'c']
list4 = listNum1 + listStr1
print list3 == list4, '\n'
# 列表竟然可以比较大小
list5 = ['b', 'c']
list6 = ['a', 'z']
print list5 > list6, '\n'
# 提取元素
list1 = listNum1 + listNum2 + listStr1 + listStr2
print list1
print list1[7]
print list1[0:4]
# 列表的拼接
list1 = [1,2,3]
list2 = [2,3,4]
list1 += list2
print list1, '\n'
# 列表的翻倍
list1 = [1,2,3]
i = 3
list1 *= i
print list1
# 添加元素的两种方法
list1 = [1,2,3]
list1 += [4]
print list1
list1 = [1,2,3]
list1.append(4)
print list1
# 取得元素个数的方法
list1 = [1,2,3]
print len(list1)
# 取得特定元素的个数
list1 = [1,2,2,3,4,4,4]
print list1.count(2)
print list1.count(4), '\n'
# 在列表中寻找特定的元素
list1 = ['a', 'b', 'c', 'a', 'b', 'c', 'a']
print list1.index('a')
print list1.index('a', 1)


相关文档:

Python模块学习

  上次学习过marshal模块用于序列化和反序列化,但marshal的功能比较薄弱,只支持部分内置数据类型的序列化/反序列化,对于用户自定义的类型就无能为力,同时marshal不支持自引用(递归引用)的对象的序列化。所以直接使用marshal来序列化/反序列化可能不是很方便。还好,python标准库提供了功能更加强大且更加安全的pickle ......

Python Re

1. Basic
参考《Python正则表达式操作指南》 
模块re,perl风格的正则表达式
regex并不能解决所有的问题,有时候还是需要代码
regex基于确定性和非确定性有限自动机
2. 字符匹配(循序渐进)
元字符
. ^ $ * + ? { [ ] \ | ( )
1) "[" 和 "]"常用来指定一个字符类别,所谓字符类别就是你想匹配的一个字符集。如[ ......

easy_install让python的包管理变得easy

Python中的easy_install工具很好用,它的作用类似于Php中的pear,或者Ruby中的gem,或者Perl中的cpan。
如果想使用easy_install工具,可以直接安装ez_setup.py
脚本,再python ez_setup.py(之前先要安装python):
安装完后,最好确保easy_install所在目录已经被加到PATH环境变量里:
Windows: C:\Python25\Scripts
Li ......

Python入门的36个例子——05 聪明的变量

# 005
# 在Python中给变量赋值时不需要声明数据类型
i = 33
print i
# 可以这样做的原因是Python把程序中遇到的任何东西都看成是对象(连int也不例外)
# 这样,在使用对象时,编译器会根据上下文的环境来调用对象自身的方法完成隐式的转换
# 你甚至可以把程序写成这样
print 3 * 'haha '
# 但若写成这样编译器就会报错 ......

学习《Python语言入门》第五章 模块

模块这东西好像没什么好讲的,无非是保存一份文件,然后在另一份文件中用import 和from ** import **(*)就行了。
这一章主要讲到了细节,导入模块Python里面是什么处理的,import 和 from ** import **有什么不一样。还有就是增加了reload()这个函数的使用说明。
以前看到哪里说尽量使用import而不要使用from ** import * ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号