xinxi={"name":"zhang yong kang","age":23,"city":'shen yang'}
print(xinxi["name"].title())
print(xinxi["age"])
print(xinxi["city"].title())
favorite_number={"zhang yong kang":3,
"xu wei nan":5,
"wang li hua":6,
"chen ren hui":8
}
print("zhang yong kang's favorite number is "+
str(favorite_number["zhang yong kang"])
+".")
print("xuweinan's favorite number is "+
str(favorite_number["xu wei nan"])+
".")
print("wang li hua's favorite number is "+
str(favorite_number["wang li hua"])+
".")
print("chen ren hui's favorite number is "+
str(favorite_number["chen ren hui"])+
".")
python_word={"print":"打印","for":"循环语句","if":"条件测试","title()":"首字母大写"}
print("print"+':\n'+python_word["print"])
print("for"+':\n'+python_word["for"])
print("if"+':\n'+python_word["print"])
print("title()"+':\n'+python_word["title()"])
python_word={"print":"打印","for":"循环语句","if":"条件测试","title()":"首字母大写"}
for word,meaning in python_word.items():
print(word+":")
print(meaning)
python_word={"print":"打印","for":"循环语句","if":"条件测试","title()":"首字母大写"}
python_word["upper()"]="全字母大写"
python_word["lower()"]="全字母小写"
python_word["{ }"]="用于字典"
python_word["[ ]"]="用于列表"
for word,meaning in python_word.items():
print(word+":")
print(meaning)
lake_nation={"nile":"Egypt","changjiang":"China","amazon":"Brazil"}
for lake,nation in lake_nation.items():
print("The "+lake+" runs through "+nation+".")
lake_nation={"nile":"Egypt","changjiang":"China","amazon":"Brazil"}
for lake in lake_nation.keys():
print(lake)
lake_nation={"nile":"Egypt","changjiang":"China","amazon":"Brazil"}
for nation in lake_nation.values():
print(nation)
favorite_languages={
'jen':'python',
'sarah':'c',
'edward':'ruby',
'phil':'python'
}
name_list=['jen','sarah','john','cris']
for name in name_list:
if name in favorite_languages:
print(name+" ,Thank you for your attention.")
else:
print(name+" ,we want to invite you to participate our investigation.")
people1={"name":"zhang yong kang","age":23,"city":'shen yang'}
people2={"name":"xu zhou","age":23,"city":'nan jing'}
people3={"name":"zhang chang long","age":47,"city":'ma an shan'}
people_all=[people1,people2,people3]
for people in people_all:
print(people)
cat={"name":"cat","owner":"zhang yong kang"}
dog={"name":"dog","owner":"wang li hua"}
pig={"name":"pig","owner":"xu wei nan"}
pets=[cat,dog,pig]
for pet in pets:
print(pet)
favorite_places={"zhang yong kang":["nan jing","sha men","shen yang"],"wang li hua":["shi jia zhuang","nan jing","bei jing"],"xu wei nan":["tian jing","ha er bin","shen yang"]}
for people, places in favorite_places.items():
print(people+":")
for place in places:
print(place)
favorite_number={"zhang yong kang":[3,4,5,6],
"xu wei nan":[1,2,3,4],
"wang li hua":[5,6,7,8],
"chen ren hui":[1,2,3]
}
for name,numbers in favorite_number.items():
print(name+":")
for number in numbers:
print(number)
cities={"nan jing":{"country":"China","population":"10000","fact":"it is hot in summer."},
"london":{"country":"England","population":"20000","fact":"it is cold in winter."},
"Los angeles":{"country":"America","population":"30000","fact":"cris live here."}
}
for city,informations in cities.items():
print(city+":")
for information in informations.values(): #第一个for循环 把cities中的值 存储到informations中
print(information)
2、学习疑问与心得(保存的心得不知道怎么消失了)
2.1、遍历字典中键-值 需要用方法.items() 只遍历键 用.keys() 只遍历值 用.values()
2.2、