摘要: #update:合并两个字典,如果有交叉就覆盖更新,没有交叉的就创建 info={ 'stu1101':'Liu Guannan', 'stu1102':'Wang Ruipu', 'stu1103':'Sun Yanan' } b={'stu1101':'Liu Guannan', 1:3, 2:5 } info.update(b) print(inf... 阅读全文
posted @ 2018-01-04 18:10 耐烦不急 阅读(256) 评论(0) 推荐(0) 编辑
摘要: #key-value 字典无下标 所以乱序,key值尽量不要取中文 person_log={ '大二':{ 'Ya Nan':['free','cute','soso'], 'Sha sha':['微胖','白白的'] }, '大四':{ 'Guan Nan':['不错',"很大"] }, ... 阅读全文
posted @ 2018-01-04 18:09 耐烦不急 阅读(3917) 评论(0) 推荐(0) 编辑
摘要: #key-value 字典无下标 所以乱序,key值尽量不要取中文 info={ 'stu1101':'Liu Guannan', 'stu1102':'Wang Ruipu', 'stu1103':'Sun Yanan', } print(info) #查找 print(info['stu1101'])#精确查找,若没有则会出错,例如print(info['stu11... 阅读全文
posted @ 2018-01-04 18:08 耐烦不急 阅读(209) 评论(0) 推荐(0) 编辑
摘要: name="my name is 齐志光qizhiguang" print(name.capitalize())#首字母变大写 print(name.count('i'))#统计字母‘i’出现的次数 print(name.center(50,'-'))#一共打印50个字符,name放中间,不够的用‘-’补上 print(name.encode(encoding="utf-8"))#字符串编码成二... 阅读全文
posted @ 2018-01-04 16:21 耐烦不急 阅读(203) 评论(0) 推荐(0) 编辑
摘要: product_list=[ ('Iphone',5800), ('Mac Pro',9800), ('Bike',800), ('Watch',10600), ('Coffee',31), ('Python Book',49) ] shopping_list=[] salary=input('Input your salary:') if sal... 阅读全文
posted @ 2018-01-03 09:37 耐烦不急 阅读(187) 评论(0) 推荐(0) 编辑
摘要: #元组只能统计和获取下表,不能插入之类的.元组和列表差不多,也是存一组数,只是它一旦创建,便不能再修改,所以又叫只读列表 names=('QiZhiguang','LiuGuannan','LiangTianqi','XiongLinyu') print(names.count('QiZhiguang')) print(names.index('LiuGuannan')) 阅读全文
posted @ 2018-01-03 09:36 耐烦不急 阅读(178) 评论(0) 推荐(0) 编辑
摘要: a=['a','d','f','g'] for i in enumerate(a): print(i) #enumerate 把列表的下表以元组的形式取出来 #结果 # (0, 'a') # (1, 'd') # (2, 'f') # (3, 'g') 阅读全文
posted @ 2018-01-03 09:30 耐烦不急 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 补充: 阅读全文
posted @ 2018-01-03 09:29 耐烦不急 阅读(202) 评论(0) 推荐(0) 编辑
摘要: import copy person=['name',['saving',100]] #3种浅copy方式 p1=copy.copy(person) p2=person[:] p3=list(person) print(p1) print(p2) print(p3) #作用举例 两人共用账户 p1[0]="齐志光" p2[0]="梁天琪" p1[1][1]=50 print(p1) print(... 阅读全文
posted @ 2018-01-03 09:29 耐烦不急 阅读(142) 评论(0) 推荐(0) 编辑
摘要: # result=值1 if 条件 else 值2 如果条件为真:result=值1,否则result=值2. a,b,c=1,3,5 d=a if b>c else c print(d) 阅读全文
posted @ 2018-01-03 09:27 耐烦不急 阅读(131) 评论(0) 推荐(0) 编辑