#用字典存储一个人的信息
personal_informations={
'first_name':'li',
'last_name':'hua',
'age':'20',
'city':'shanghai',
'constellation':'pisces',
}
print(personal_informations)
#存储多个人喜欢的数字,并单独打印键和值
favorite_number={
'curry':3,
'mr.chen':8,
'flower':3,
'lihua':5,
'abc':7,
}
for value in favorite_number:
print(value+"'s favorite number is "+str(favorite_number[value]))
print(favorite_number['mr.chen'])
#遍历键
for name in favorite_number.keys():
print(name)
#遍历值
for value in favorite_number.values():
print(value)
#对已参与的人员表示感谢,邀请没参与调查的人员
personnel_list=['A','B','C','D','E','F','G']
favorite_languages={
'A':"python",
'D':'python',
'B':'c',
'C':'perl',
}
for name in favorite_languages.keys():
if name in personnel_list:
print(name.title()+", thanks you very much for your participation")
a=list(favorite_languages.keys()) #当字典中的键比较少时 可以将字典转化为列表
for value in personnel_list:
if value not in a:
print(value.title() +',it is my pleasure if you can participation in our investigate')
#将三个人的信息字典存储在列表中,并遍历这个列表 打印
user_1={
'first_name':'li',
'last_name':'hua',
'age':'20',
'city':'shanghai',
}
user_2={
'firstname':'li',
'lastname':"curry",
'hometown':'San Francisco',
}
user_3={
'firstname':'li',
'lastname':"curry",
'hometown':'San Francisco',
}
users=[user_1,user_2,user_3]
for user in users:
print(user)
分享到:
相关推荐
面向ARC GIS的python语言开发与实例数据
python_mini_exercises
python_the_hard_way_exercises
python_leetcode_exercises:Python3中的Leetcode算法编码练习的集合
Python_3_Classes_Codecademy_Exercises 有关Python 3中的类,方法,多态性和继承的示例和注释。
python-javascript_coding-exercises
C语言程序设计教程课件:4_ab_Exercises_Statements.ppt
These notes are designed for someone new to statistical computing wishing to develop a set of skills necessary to perform original research using Python. They should also be useful for students, ...
CAA_V5_For_CATIA_Foundations_Exercises CAA_V5_For_CATIA_Foundations_Exercises CAtia 二次开发,基于CAA
zenoss_event_management_exercises_toc
python编码练习 python编码练习。
LV Core 3 Exercises manual
NumPy 100 exercises, let you learn more about NumPy.
PsimBook Exercises(speed regulation DC Motor)
Solutions_to_Exercises
Answers to Selected Exercises Chapter 2 5. Loops and numbers a) i = 0 while i i += 1 b) for i in range(11): pass 6. Conditionals n = int(raw_input('enter a number: ')) if n print 'negative' elif n >...
CAA_V5_for_CATIA_Getting_Started_Exercises.pdf