python笔记:容器 1 添加元素testList = [] testList.append("hello") print testList[0] test2 = ["my","world"] testList.extend(test2) print testList2 删除元素del testList[0] print testList3 队列注:系统提供包Queue,实现一个阻塞队列。在《线程》中实现线程池的时候使用,可以参考一下。#队列 que=[] que.append("hello") que.append("world") item = que.pop(0) print item print que4 字典#字典 #不要用 dict, list,file, bool, str, input, len 这样的内建类型为变量命名 mydict={} mydict["yzh"] = "yzh" #判定是否存在 if "yzh" in mydict: print mydict["yzh"] #删除内容 del mydict["yzh"] #再判定 if "yzh" in mydict: print mydict["yzh"] else: print "not in dict" mydict["a"]=1 mydict["b"]=2 #遍历字典 for k in mydict: print k,mydict[k] 来自 大脸猫 写于 2016-05-17 14:58 -- 更新于2020-10-19 13:06 -- 0 条评论