我是靠谱客的博主 健忘唇膏,最近开发中收集的这篇文章主要介绍Python编程 从入门到实践 第三章习题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

3-1 姓名

>>> name = ['Alex', 'Leo', 'Mike']
>>> print(name[0])
Alex
>>> print(name[1])
Leo
>>> print(name[2])
Mike

3-2 问候语

>>> message = 'Hello, '+name[0] +', how are you ?'
>>> print(message)
Hello, Alex, how are you ?
>>> print(message1)
Hello, Leo, how are you ?
>>> message2 = 'Hello, '+name[2] +', how are you ?'
>>> print(message2)
Hello, Mike, how are you ?

3-4 嘉宾名单

>>> list = ['Alex', 'Demmo', 'Mike']
>>> print(list[0] + ',May I have the honour to have a dinner with you ?')
Alex,May I have the honour to have a dinner with you ?
>>> print(list[1] + ',May I have the honour to have a dinner with you ?')
Demmo,May I have the honour to have a dinner with you ?
>>> print(list[2] + ',May I have the honour to have a dinner with you ?')
Mike,May I have the honour to have a dinner with you ?

3-5 修改嘉宾名单

>>> list = ['Alex', 'Demmo', 'Mike']
>>> print(list[0] + " is unable to attent the dinner !")
Alex is unable to attent the dinner !
>>> list[0] = 'Leo'
>>> print(list[0] + ',May I have the honour to have a dinner with you ?')
Leo,May I have the honour to have a dinner with you ?
>>> print(list[1] + ',May I have the honour to have a dinner with you ?')
Demmo,May I have the honour to have a dinner with you ?
>>> print(list[2] + ',May I have the honour to have a dinner with you ?')
Mike,May I have the honour to have a dinner with you ?

3-6 添加嘉宾

>>> list = ['Alex', 'Demmo', 'Mike']
>>> print('We can invite more people to join us!')
We can invite more people to join us!
>>> list.insert(0,'Jack')
>>> list.insert(2,'Bessie')
>>> list.append('Lili')
>>> list
['Jack', 'Alex', 'Bessie', 'Demmo', 'Mike', 'Lili']
>>> print(list[0] + ',May I have the honour to have a dinner with you ?')
Jack,May I have the honour to have a dinner with you ?
>>> print(list[1] + ',May I have the honour to have a dinner with you ?')
Alex,May I have the honour to have a dinner with you ?
>>> print(list[2] + ',May I have the honour to have a dinner with you ?')
Bessie,May I have the honour to have a dinner with you ?
>>> print(list[3] + ',May I have the honour to have a dinner with you ?')
Demmo,May I have the honour to have a dinner with you ?
>>> print(list[4] + ',May I have the honour to have a dinner with you ?')
Mike,May I have the honour to have a dinner with you ?
>>> print(list[5] + ',May I have the honour to have a dinner with you ?')
Lili,May I have the honour to have a dinner with you ?

3-8 放眼望世界

>>> travel_location = ['Guangzhou','Wuhan','Beijing','Shanghai','Nanjing']
>>> print(travel_location)                
['Guangzhou', 'Wuhan', 'Beijing', 'Shanghai', 'Nanjing']            #原始顺序
>>> print(sorted(travel_location))
['Beijing', 'Guangzhou', 'Nanjing', 'Shanghai', 'Wuhan']            #Sorted()排序
>>> print(travel_location)
['Guangzhou', 'Wuhan', 'Beijing', 'Shanghai', 'Nanjing']            #sorted()排序未改变原始顺序 核查
>>> travel_location.reverse()        
>>> print(travel_location)
['Nanjing', 'Shanghai', 'Beijing', 'Wuhan', 'Guangzhou']            #reverse()改变原始顺序
>>> travel_location.reverse()
>>> print(travel_location)
['Guangzhou', 'Wuhan', 'Beijing', 'Shanghai', 'Nanjing']            #reverse()恢复原始顺序
>>> travel_location.sort()
>>> print(travel_location)
['Beijing', 'Guangzhou', 'Nanjing', 'Shanghai', 'Wuhan']            #sort()改变顺序
>>> travel_location.sort(reverse = True)
>>> print(travel_location)
['Wuhan', 'Shanghai', 'Nanjing', 'Guangzhou', 'Beijing']            #按与字母顺序相反的顺序排列





最后

以上就是健忘唇膏为你收集整理的Python编程 从入门到实践 第三章习题的全部内容,希望文章能够帮你解决Python编程 从入门到实践 第三章习题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部