day3-python学习笔记

Posted Flynn丶傅

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了day3-python学习笔记相关的知识,希望对你有一定的参考价值。

一.字典操作
# 字符串,整型,list,字典
# stus = [
# [‘小傅‘,‘25‘,‘nan‘,‘xxx‘,‘20k‘]
# [‘小傅‘,‘25‘,‘nan‘,‘xxx‘,‘20k‘]
# [‘小傅‘,‘25‘,‘nan‘,‘xxx‘,‘20k‘]
# [‘小傅‘,‘25‘,‘nan‘,‘xxx‘,‘20k‘]

#字典 k=v,取值方便,速度快
d = {‘name‘:‘小傅‘,
‘age‘:18,
‘sex‘:‘男‘,
‘addr‘:‘番禺区‘,
‘money‘:100000
}
#字典 查
#print(d[‘name‘])
#print(d[‘money‘])
#print(d[‘haha‘])如果写了不存在的key,会报错
# print(d.get(‘sdasd‘))#查询无此key,返回none,不存在的key,不会报错
# print(d.get(‘sdasd‘,‘找不到‘))#

#字典 增加
# d[‘height‘]=178
#d.setdefault(‘weight‘,130) 只能增加不能修改
# #字典是无序的,
# print(d)

#字典 修改
# d[‘height‘]=200#如果这个key存在的话,修改他的值,如果key不存在的话,新增一个

#字典 删除
# d.pop(‘sex‘)#删除某个key
#d.popitem()#随机删除一个
#del d[‘age‘]
#d.clear()#清空字典
# print(d.keys())
# print(d.values())
# d.hash_key(‘addr‘)#python2里面字典有这个方法,有没有这个key
# if ‘addr‘ in d:
# print(‘addr‘)

#for k,v in d.items():#循环字典,把字典key,value转成二维数组,性能差
#print(d.items())

# for k in d:#性能好
# print(k,d[k])
# print(k,d.get(k))

res = list(d.items())
print(res[1])
# # int()#转换成int类型
# # str()#转换成字符串类型
# # list()#转换成list类型
# res = list(d.items())
# print(res[2])

#数组,字典嵌套查询等

# stus=[

# {‘name‘:‘彬‘,
#      ‘age‘:18,
# ‘sex‘:‘男‘,
# ‘addr‘:‘昌平区‘,
# ‘money‘:100000,
# ‘jinku‘:{
# ‘$‘: 50000,
# ‘¥‘:8000
#
# }
# },
# {‘name‘:‘彬1‘,
# ‘age‘:18,
# ‘sex‘:‘男‘,
# ‘addr‘:‘昌平区‘,
# ‘money‘:100000,
# ‘bag‘:{
# ‘nike‘:‘一车‘
#
# }
# }
# ]
# print(stus[0][‘jinku‘][‘¥‘])
# #print(stus[‘tlx‘][‘money‘])
# print(stus[1][‘bag‘][‘nike‘])

stus = {
‘ybq‘: {
‘age‘: 18,
‘sex‘: ‘男‘,
‘addr‘: ‘昌平区‘,
‘money‘: 10000000,
‘jinku‘: {
‘建行卡‘: 80000,
‘工商卡‘: 800000,
‘招商卡‘: 8000000
}
},
‘tlx‘: {
‘age‘: 19,
‘sex‘: ‘女‘,
‘addr‘: ‘昌平区‘,
‘money‘: 10000000,
‘huazhuangpin‘:
[‘cha‘, ‘haha‘]

},
‘mpp‘: {
‘age‘: 19,
‘sex‘: ‘女‘,
‘addr‘: ‘昌平区‘,
‘money‘: 10000000,
"bag": {
‘lv‘: ‘一车‘,
‘鳄鱼‘: 10
}
},
}
# print(stus[‘tlx‘][‘money‘])
# print(stus[‘mpp‘][‘bag‘].keys())
#
# all_money = stus[‘ybq‘][‘jinku‘].values()
# # print(all_money)
# # print(sum(all_money))
# sum_money = 0
# for money in all_money:
# sum_money = sum_money + money
# print(sum_money)

#print(stus[‘tlx‘][‘huazhuangpin‘][1])



# all_money = stus[‘ybq‘][‘jinku‘].values()
# #print(sum(all_money))
# sum_money = 0
# for money in all_money:
# sum_money=sum_money +money
#
# print(sum_money)
print(stus[‘tlx‘][‘huazhuangpin‘][1])












































































































































以上是关于day3-python学习笔记的主要内容,如果未能解决你的问题,请参考以下文章

DOM探索之基础详解——学习笔记

学习笔记 链接

ReactJs学习笔记01

OpenCV 学习笔记(颜色直方图计算 calcHist)

JSP 学习笔记

vue视频学习笔记05