摘要: import collections as con # 有序添加和取字典元素 ord = con.OrderedDict() ord['a'] = 1 ord['b'] = 2 ord['c'] = 3 print(ord, 'ordereddict') # 移动某元素到最后 ord.move_to_end('a') print(ord, 'move_to_end') 阅读全文
posted @ 2017-03-12 18:18 破斧呈粥 阅读(149) 评论(0) 推荐(0) 编辑
摘要: import collections as con #默认字典数据类型(参数填数据类型) dic = con.defaultdict(list) dic['a'].append(55) print(dic,'defaultdict') 阅读全文
posted @ 2017-03-12 18:17 破斧呈粥 阅读(149) 评论(0) 推荐(0) 编辑
摘要: import collections as con #用namedtyuple创建一个类 classtuple = con.namedtuple('classtuple', ['x', 'y', 'z']) #用这个类创建可命名元组对象 namet= classtuple(1,2,3) print 阅读全文
posted @ 2017-03-12 18:15 破斧呈粥 阅读(96) 评论(0) 推荐(0) 编辑
摘要: import collections as con dq = con.deque() # 右侧添加 dq.append(1) print(dq, 'append') # 左侧添加 dq.appendleft(2) print(dq, dq[0], 'appendleft') # 清空队列 # dq.clear() # 队列某元素数量 print(dq.count(1), 'count'... 阅读全文
posted @ 2017-03-12 18:12 破斧呈粥 阅读(111) 评论(0) 推荐(0) 编辑
摘要: import queue # 参数指定队列大小 q = queue.Queue(10) print(q) # 查看当前队列数量 print(q.qsize(), 'qsize') # 当前队列是否为空 print(q.empty()) #当前队列数量是否已达到队列最大值 print(q.full(),'full') #加入一个队列成员 q.put(10) q.put(1) print(... 阅读全文
posted @ 2017-03-12 18:11 破斧呈粥 阅读(114) 评论(0) 推荐(0) 编辑
摘要: import copy # 浅拷贝 # copy.copy() # 深拷贝 # copy.deepcopy() # 赋值 s1 = '1234' s2 = 456 t1 = s1 t2 = s2 c1 = copy.copy(s1) c2 = copy.deepcopy(s1) print(id(s1), id(t1), id(c1), id(c2), id(s2), id(t2)) #... 阅读全文
posted @ 2017-03-12 18:05 破斧呈粥 阅读(151) 评论(0) 推荐(0) 编辑
摘要: # 无参数 def fun1(): print(1, '无参数') fun1() # 带返回值 def fun2(): return 999 print(fun2(), '带返回值') # 有参数 def fun3(a, b): print(a, b, '带参数') fun3(1, 3) # 默认参数 def fun4(a, b=333): print... 阅读全文
posted @ 2017-03-12 18:03 破斧呈粥 阅读(557) 评论(0) 推荐(0) 编辑
摘要: ''' abs() dict() help() min() setattr() all() dir() hex() next() slice() any() divmod() id() object() sorted() ascii() enumerate() input() oct() staticmethod() bin() eval() int() open() str() bool() ... 阅读全文
posted @ 2017-03-12 18:01 破斧呈粥 阅读(136) 评论(0) 推荐(0) 编辑
摘要: luck_num = 10 num = 0 while luck_num != num: num = int(input('please input you num:')) if num > luck_num: print('Greater than lucknum') elif num luck_num: print('Greater... 阅读全文
posted @ 2017-03-03 22:14 破斧呈粥 阅读(114) 评论(0) 推荐(0) 编辑
摘要: import os # 判断文件是否存在 if not os.path.exists('error.txt'): f = open('error.txt', 'w') listname = [] else: # 读取文件内容 f = open('error.txt', 'r') listname = f.readlines() f.close() #... 阅读全文
posted @ 2017-03-03 22:14 破斧呈粥 阅读(148) 评论(0) 推荐(0) 编辑