6-1人
6-2喜欢的数字
6-3 词汇表
6-4词汇表2
6-5河流
6-6调查
6-7人
6-8宠物
6-9喜欢的地方
6-10喜欢的数字
6-11城市
6-12扩展
people = { 'first_name':'Lucy', 'last_name': 'Zheng' , 'age': 20 , 'city': 'Guangzhou'}
print (people)
6-2喜欢的数字
num = {'Lucy': 17 , 'Peppa': 2 , 'George': 4 , 'LittlePig': 7}
print (num)
6-3 词汇表
vo = {
'del': 'delete sth',
'.lower()' : 'the lower case of the string',
'.upper()' : 'the upper case of the string',
'if' : 'to judge',
'len' : 'the length of sth'
}
for key in vo.keys():
print(key+' : '+vo[key])
6-4词汇表2
vo = {
'del': 'delete sth',
'.lower()' : 'the lower case of the string',
'.upper()' : 'the upper case of the string',
'if' : 'to judge',
'len' : 'the length of sth',
'print': 'print sth on the screen',
'.key()': 'find the keys of the vocabulary',
'.items' : 'find the items of the vocabulary',
'.values()' : 'find the values of the vocabulary',
'else' : 'to judge'
}
for key,value in vo.items():
print(key+' : '+value)
6-5河流
river = {
'nile' : 'Egypt',
'Times' : 'England',
'The Changjiang river' : 'China'
}
for key,value in river.items():
print('The '+ key.title() + ' runs through ' + value)
for key in river.keys():
print(key)
for value in river.values():
print(value)
6-6调查
people = ['Peppa','George','Bob']
serve = {'Bob':'Have done'}
for peo in people:
if peo in serve.keys():
print(peo + ',thank you for attending our serving.')
else:
print(peo + ',please attend our serving.')
6-7人
people1 = { 'first_name':'Lucy', 'last_name': 'Zheng' , 'age': 20 , 'city': 'Guangzhou'}
people2 = { 'first_name':'Jair', 'last_name': 'Zhu' , 'age': 20 , 'city': 'Guangzhou'}
people3 = { 'first_name':'David', 'last_name': 'Li' , 'age': 19 , 'city': 'Guangzhou'}
people = [people1,people2,people3]
for pe in people:
print(pe)
6-8宠物
Candy = {'type': 'cat' , 'owner' : 'Bob'}
Peppa = {'type': 'pig' , 'owner' : 'Kevin'}
Suxy = {'type': 'sheep' , 'owner' : 'Stuart'}
pets = [Candy,Peppa,Suxy]
for pet in pets:
print(pet)
6-9喜欢的地方
favourite_places = {
'Bob' : ['Beijing','Shanghai','Guangzhou'],
'Kevin' : ['Chongqing','Xian','Harbin'],
'Stuart' : ['Chengdu' ,'Guilin' ,'Xiamen']
}
for key,value in favourite_places.items():
print (key + ' ' , value)
6-10喜欢的数字
num = {
'Lucy': [17,18,19],
'Peppa': [2,3,4],
'George': [4,5,6],
'LittlePig': [7,8,9]
}
for key,value in num.items():
print(key,value)
6-11城市
cities = {
'Beijing': { 'Country':'China','population':21730000,'fact':'the center of politics'},
'Shanghai': { 'Country':'China','population':24200000,'fact':'the center of economy'},
'Guangzhou' : {'Country':'China','population':14490000,'fact':'the center of exportation'},
}
for key,value in cities.items():
print (key,' ',value)
6-12扩展
favourite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
favourite_languages['Bob'] = 'php'
for key,value in favourite_languages.items():
print (key,' ',value)