字典:当索引不好用时
映射
耐克成为key,口号成为value
brand = ['李宁','耐克','阿迪达斯']
slogan = ['一切皆有可能','Just do it','impossible is nothing']
print('耐克的口号是:',slogan[brand.index('耐克')])
dict1 = {'李宁':'一切皆有可能','耐克':'Just do it','阿迪达斯':'impossible is nothing'}
print('耐克的口号是:',dict1['耐克'])
耐克的口号是: Just do it
耐克的口号是: Just do it
dict2 = {1:'one',2:'two',3:'three'}
print(dict2[2])
dict3 = dict((('F',70),('i',105),('s',115)))
print(dict3)
dict4 = dict(小甲鱼='让编程改变世界',你='狗')
print(dict4)
dict4['你'] = '狗狗啊'
print(dict4)
dict4['wqe'] = '仙女'
print(dict4)
dict5={}
print(dict5.fromkeys((1,2,3),'number'))
print(dict5.fromkeys((1,2,3),('1','2',3)))
for eachkey in dict4.keys():
print(eachkey)
for eachvalue in dict4.values():
print(eachvalue)
for eachitem in dict4.items():
print(eachitem)
print(dict2.get(3,'木有'))
print(dict2.get(4,'木有'))
print(3 in dict2)
print(4 in dict2)
two
{'F': 70, 'i': 105, 's': 115}
{'小甲鱼': '让编程改变世界', '你': '狗'}
{'小甲鱼': '让编程改变世界', '你': '狗狗啊'}
{'小甲鱼': '让编程改变世界', '你': '狗狗啊', 'wqe': '仙女'}
{1: 'number', 2: 'number', 3: 'number'}
{1: ('1', '2', 3), 2: ('1', '2', 3), 3: ('1', '2', 3)}
小甲鱼
你
wqe
让编程改变世界
狗狗啊
仙女
('小甲鱼', '让编程改变世界')
('你', '狗狗啊')
('wqe', '仙女')
three
木有
True
False
进程已结束,退出代码0
|