# dic = {'k1':'v1','k2':'v2','k3':'v3'}
# print(dic)
# #循环遍历出所有的key
# for k in dic:
# print(k)
# #循环遍历出所有的value
# for k in dic:
# print(dic[k])
# #循环遍历出所有的key和value
# for k in dic:
# print(k,dic[k])
#添加一个键值对
# dic['k4'] = 'v4'
# 删除一个键值对
# dic.pop('k1')
# 删除键’k5‘对应的值,若不存在,则不报错,并返回None
# print(dic.get('k5'))
# 获取’k2‘对应的值
# print(dic.get('k2'))
# 获取键’k6‘对应的值,若不存在,则不报错,并返回None
# print(dic.get('k6'))
# dic2 = {'k1':'v111','a':'b'}
# dic2.update(dic)
#
# print(dic2)
# print(dic)
# s = 'kjklsj'
# print(s.upper())
# print(s)
# lis = [['k',['qwe',20,{'k1':['tt',3,'1']},89],'ab']]
#将tt用两种方法变成大写
# lis[0][1][2]['k1'][0] = lis[0][1][2]['k1'][0].upper()#法一
# lis[0][1][2]['k1'][0] = 'TT'#法二
#将列表中数字3变成字符串'100'两种方法
# lis[0][1][2]['k1'][1] = '100'法一
# lis[0][1][2]['k1'] = ['tt','100','1']法二
#将列表中字符串’1‘变成数字101两种方法
# lis[0][1][2]['k1'][2] = 101法一
# lis[0][1][2]['k1'] = ['tt','100',101]法二
# print(lis)
li = [1,2,3,'a','b,',4,'c']
dic = {}
dic.setdefault('k1',[])
dic['k1'] = li[1::2]
for i in li[1::2]:
dic['k1'].append(i)
print(dic)
python全栈笔记-day03-dictionary
最新推荐文章于 2024-07-09 15:22:28 发布