博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2.20
阅读量:4910 次
发布时间:2019-06-11

本文共 3950 字,大约阅读时间需要 13 分钟。

 

 

 

1 python_vocabulary = {
'import this': 'Zen of python', 2 'insert': '插入', 3 'range': '范围', 4 'popped': '术语弹出' 5 } 6 print(python_vocabulary) 7 8 for vocabulary, means in python_vocabulary.items(): # 第二部分包含字典名和方法items() 9 print('\nvocabulary: ' + vocabulary) 10 print('means: ' + means) 11 12 python_vocabulary['append'] = '向列表中添加元素' 13 python_vocabulary['set()'] = '剔除重复的值' 14 python_vocabulary['keys()'] = '字典键' 15 python_vocabulary['values()'] = '字典值' 16 python_vocabulary['items()'] = '无法描述(重点)' 17 18 for key,values in python_vocabulary.items(): 19 print('\nVocabulary: ' + key) 20 print('\nmeans: ' + values) 21 22 rivars = {
'China':'changjiang','nile':'egypt','brazil':'amazon'} 23 for country,rivar in rivars.items(): 24 print('The '+ rivar.title() + ' runs through ' + country.title() + '.') 25 26 # for country in rivars.items(): #.keys()与.value() 位置和输入错误 下文订正 27 # print (rivars.key()) 28 # for rivar in rivars.items(): 29 # print (rivars.value()) 30 for country in rivars.keys(): 31 print (country.title()) 32 for rivar in rivars.values(): 33 print (rivar.title()) #.title()少输入括号后 显示异常 34 #
35 #
36 #
37 #
38 #
39 #
40 41 aliens = [] 42 for alien_number in range(30): 43 new_alien = { 'color': 'green', 'points': 5, 'speed': 'slow'} 44 aliens.append(new_alien) 45 for alien in aliens[:5]: 46 print(alien) 47 print('...') 48 print(str(len(aliens))) 49 50 for alien in aliens[0:3]: # 切片语法还未熟练 51 if alien['color'] == 'green': 52 alien['color'] = 'yellow' 53 alien['speed'] == 'medium' 54 alien['points'] = 10 55 56 for alien in aliens[:5]: 57 print(alien) # 多打s则变为打印列表 58 59 favorite_languages = { 60 'jen': ['python', 'ruby'], 61 'sarah': ['c'], 62 'edward': ['ruby', 'go'], 63 'phil': ['python', 'haskell'], 64 } 65 for name, languages in favorite_languages.items(): 66 if len(languages) >= 2: 67 print("\n" + name.title() + "'s favorite languages are:") 68 else: 69 print("\n" + name.title() + "'s favorite languages is:") 70 for language in languages:#此处for循环不可与上个for循环缩进相同 71 print("\t" + language.title()) 72 73 # 练习6-1 6-1 人 :使用一个字典来存储一个熟人的信息,包括名、姓、年龄和居住的城市。该字典应包含键 74 # first_name 、last_name 、age 和city 。将存储在该字典中的每项信息都打印出来。 75 76 shiitakeimoto = { 'first_name': 'ying', 'last_name': 'ying', 'age': 22, 'city': 'fuzhou'} 77 ergou = { 'first_name': 'lin', 'last_name': 'zhu', 'age': 24, 'city': 'shanghai'} 78 erzi = { 'first_name': 'junqin', 'last_name': 'cai', 'age': 25, 'city': 'kunming'} 79 80 people = [shiitakeimoto, ergou, erzi] 81 for name in people: 82 print(name) 83 #错误例子 84 # nike = {'zhonglei':'taidi','zhuern':'ergou'} 85 # doudou = {'zhonglei':'yingduan','zhuren':'momoe'} 86 # pingtou = {'zhonglei':'shuilan','zhuren':'erzi'} 87 88 pets = { 'nike': { 'zhonglei': 'taidi', 'zhuern': 'ergou'}, 'doudou': { 'zhonglei': 'yingduan', 'zhuren': 'momoe'}, 89 'pingtou': { 'zhonglei': 'shuilan', 'zhuren': 'erzi'}, } 90 91 # pets = {nike,doudou,pingtou} 92 print(pets) 93 94 users = { 'aeinstein': { 'first': 'albert', 'last': 'einstein', 'location': 'princeton', }, 95 'mcurie': { 'first': 'marie', 'last': 'curie', 'location': 'paris', }, } 96 print(users) 97 98 favorite_places = { 'ergou':['suzhou','shanxi','shenzhen'],'erzi':['osaka','kyoto'],'momoe':['liancang']} 99 favorite_places['shiitakeimoto'] = ['taiba','suizokukan','jinnjya']100 for name,places in favorite_places.items():101 if len(places) >= 2:102 print(name.title() + '\'s favorite places are:' )103 else:104 print(name.title() + '\'s favorite place')105 for place in places:106 print('\t' + place.title())107 108 109 message = input("Tell me something, and I will repeat it back to you: ")110 print(message)
View Code

 

转载于:https://www.cnblogs.com/phyllissRyo/p/10411647.html

你可能感兴趣的文章
[深入React] 3.JSX的神秘面纱
查看>>
【codevs 2306】【bzoj 1877】[SDOI 2009]晨跑(费用流)
查看>>
第一次OO作业总结
查看>>
python 怎么画图
查看>>
EntityFramework Linq to Entities Left join and filter Include
查看>>
C#中的结构体与类的区别
查看>>
8th week blog 1
查看>>
BZOJ3991 [SDOI2015]寻宝游戏
查看>>
estt
查看>>
关于Java语言中那些修饰符
查看>>
LeetCode-380 Insert Delete GetRandom O(1)
查看>>
Flink – Trigger,Evictor
查看>>
Recurrent NN vs Recursive NN
查看>>
如何在vue+element中实现选择框和穿梭框的根据拼音以及拼音首字母以及汉字的模糊搜索...
查看>>
.net面试题
查看>>
php读取不到https的域名
查看>>
2018-01-11 Antlr4实现数学四则运算
查看>>
centos7上基于kubernetes的docker集群管理
查看>>
【转】七个受用一生的心理寓言
查看>>
nginx
查看>>