列表的使用: list.append(value) 向列表增加元素 list.insert(index, value) 向列表指定元素插入元素 list.extend(newlist) 用新的列表扩展列表 list.remove(value) 删除列表的指定值 del list[index] 删除指定索引的值 list.pop() 删除列表最后一个值 list.reverse() 列表反转 list.sort() 列表元素按ASCII码排序 list.count(value) 统计元素的个数 l…
1. 体验多进程的运行速度 #!/usr/bin/env python # _*_ coding:UTF-8 _*_ from multiprocessing import Pool import time def foo(n): time.sleep(1) return n * n if __name__ == "__main__": pool = Pool(10) data_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # 这里只需要等待1S就能得到…
1.常见的错误 TypeError 类型错误 NameError 没有该变量 ValueError 不期望的值 AttributeError 没有该属性 UnboundLocalError 没有该局部变量 ImportError 没有该模块 IOError 打不开文件 IndexError 列表没有该下标 KeyError 字典没有该键 IndentationError 代码没有对齐 SyntaxError 语法错误 KeyboardError Ctrl+C被按下 2.示例代码 #!/usr/b…
例子: sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退出时exit(0) sys.version 获取Python解释程序的版本信息 sys.maxint 最大的Int值 sys.maxunicode 最大的Unicode值 sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值 sys.platform 返回操作系统平台名称 sys.stdout.write('please:') val = sys.stdi…
序列化是使用二进制的方式加密列表,字典或集合,反序列化是解密的过程:序列化开启了两个独立进程进行数据交互的通路 使用pickle进行序列化和反序列化 例如: pickle_test.py #!/usr/bin/env python # _*_ coding:UTF-8 _*_ import pickle if __name__ == "__main__": name_list = ["liudaoqiang", 11, 22, "success"…
1.基本内置函数 help() 帮助文档 dir() 列出当前文件的所有变量和方法 vars() 列出当前文件的所有变量及其值 type() 返回变量的类型 id() 返回变量的内存地址 len() 返回变量的长度 from package import module 导入模块 reload(package.module) 重新加载模块 2.基本运算内置函数 bool() 转化为bool值 abs() 获取绝对值 divmod() 返回商和余数的元组 max() 返回最大值 min() 返回最小…
1.可变参数,将传参自动汇总成列表 2.可变参数,将参数自动汇总成字典 实战如下: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ def show(*args): for arg in args: print arg def show2(**kargs): for item in kargs.items(): print item if __name__ == "__main__": show('daoqiang', 'zhangsan',…
dict = {key1:value1, key2:value2} 定义字典 dict[key] = value 设置字典中指定健的值 dict.pop(key) 删除字典中指定健 dict.popitem() 随机删除字典中的健 dict.clear() 清空元组 dict.update(dict2) 使用另一个字典更新, dict.setdefault(key, value) 如果该键存在则不设置,如果该键不存在则设置 dict.get(key, default_value) 获取指定健的值…
第一天   文件IO处理 1.读文件实例 file_split.python f = file('myFile.txt', 'r') for line in f.readlines(): line = line.strip('\n').split(':') print line myFile.txt ## # User Database # # Note that this file is consulted directly only when the system is running #…
1. 线程的创建与运行 #!/usr/bin/env python # _*_ coding:UTF-8 _*_ from threading import Thread def foo(param1, param2): print "{0}{1}".format(param1, param2) if __name__ == "__main__": print "main thread running" thread = Thread(targe…