摘要: __str__:用于在print(对象)时,直接打印__str__的返回值 __fun_name:私有方法 __del__:对象销毁时调用的方法 __new__:根据类对象创建实例对象(发生在__init__之前) 比如代码中定义了Dog类,在类定义结束后创建了类对象,然后调用Dog()创建实例对象 阅读全文
posted @ 2018-01-09 15:33 许小伍 阅读(339) 评论(0) 推荐(0) 编辑
摘要: a = 4b = 5 #第1种c = 0c = aa = bb = c #第2种a = a+bb = a-ba = a-b #第3种a,b = b,a print("a=%d,b=%d"%(a,b)) 阅读全文
posted @ 2017-12-31 23:06 许小伍 阅读(736) 评论(0) 推荐(0) 编辑
摘要: def test(a, b, func): result = func(a, b) print(result) test(10, 15, lambda x, y: x + y) #coding=utf-8 #python2需要加上coding=utf-8 def test(a, b, func): result = func(a, b) return ... 阅读全文
posted @ 2017-12-31 23:02 许小伍 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1,2分别赋值给a,b,剩下的参数以元组的形式赋值给args 字典形式参数: 传入元组和字典: 阅读全文
posted @ 2017-12-31 22:28 许小伍 阅读(10899) 评论(0) 推荐(1) 编辑
摘要: 添加新的元素 append() insert() extend() +号 删除元素 pop() remove() del xxx[index] 修改 xxx[index] = value 查找 in、not in if value in arr: ...... 阅读全文
posted @ 2017-12-31 14:28 许小伍 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 1 import contextlib 2 from queue import Queue 3 4 @contextlib.contextmanager 5 def myOpen(file): 6 f = open(file) 7 try: 8 yield f #返回f到with...as..语句中的f 9 finally: 10 ... 阅读全文
posted @ 2017-06-18 19:27 许小伍 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 1 from multiprocessing import Pool 2 from time import sleep 3 def Foo(i): 4 sleep(1) 5 print(i) 6 7 8 if __name__ == "__main__": 9 #5个线程会同时执行 10 pool = Pool(5) 11 12 f... 阅读全文
posted @ 2017-06-18 13:01 许小伍 阅读(592) 评论(0) 推荐(0) 编辑
摘要: pass 阅读全文
posted @ 2017-06-17 12:33 许小伍 阅读(120) 评论(0) 推荐(0) 编辑
摘要: pass 阅读全文
posted @ 2017-06-17 12:33 许小伍 阅读(82) 评论(0) 推荐(0) 编辑
摘要: pass 阅读全文
posted @ 2017-06-17 12:30 许小伍 阅读(109) 评论(0) 推荐(0) 编辑