摘要: fromkeys(seq,b) 方法用于创建一个新字典,以 seq 中元素作为key值,b作为字典中键对应的value seq = ('Google', 'Runoob', 'Taobao') this=dict.fromkeys(seq) this {'Google': None, 'Runoob 阅读全文
posted @ 2022-02-11 16:44 keep2021 阅读(48) 评论(0) 推荐(0) 编辑
摘要: 1、自己写脚本去重 new_list=[] for i in array: if i not in new_list: new_list.append(i) 2、用集合set去重 先转为集合去重,再转为list a=[2,3,4,1,2,3,4] set(a) {1, 2, 3, 4} list(s 阅读全文
posted @ 2022-02-11 16:37 keep2021 阅读(590) 评论(0) 推荐(0) 编辑
摘要: find 和 index 都是用来搜索目标字符串的位置 区别: 如果目标字母不存在,find 返回 -1,index 返回异常 a='sdfdjfjofe' a.find("d") 1 a.index("d") 1 a.find("x") -1 a.index("x") Traceback (mos 阅读全文
posted @ 2022-02-11 15:37 keep2021 阅读(630) 评论(0) 推荐(0) 编辑
摘要: is:判断id号是否相等,id() 获取对象的内存地址 == : 判断值是否相等 a=1000 b=1000 a is b False id(a) 2108025587312 id(b) 2108025587504 a==b True 阅读全文
posted @ 2022-02-11 15:31 keep2021 阅读(25) 评论(0) 推荐(0) 编辑