python入门——列表简介的相关练习
2018-03-12 17:25
686 查看
1.元素的增删
friends = [ 'alice', 'bob', 'cindy', 'Tom']
for person in friends:
print(person.title()+',how are you?\n')
print( friends[1].title()+' is not here, but lucy have come here.\n')
friends[1] = 'lucy'
print('See, xiaoming comes here too!\n')
friends.insert(0,'xiaoming')
print("Wo, is that nancy?\n")
friends.insert(int(len(friends)/2),'nancy')
print('And that girl who is singing is xiaohong.\n')
friends.append('xiaohong')
print('party is over!\n')
friends.pop()
friends.pop()
friends.pop()
friends.pop()
del friends[-1]
del friends[-1]
friends.remove('xiaoming')
print(friends)
输出结果:
2.列表排序
plance = [ 'kunming', 'xihu', 'shanghai', 'beijing', 'chendu']
print(plance)
print('\n')
print(sorted(plance))
print('\n')
print(plance)
print('\n')
print(sorted(plance,reverse=True))
print('\n')
plance.reverse()
print(plance)
plance.reverse()
print(plance)
plance.sort()
print(plance)
输出结果:
friends = [ 'alice', 'bob', 'cindy', 'Tom']
for person in friends:
print(person.title()+',how are you?\n')
print( friends[1].title()+' is not here, but lucy have come here.\n')
friends[1] = 'lucy'
print('See, xiaoming comes here too!\n')
friends.insert(0,'xiaoming')
print("Wo, is that nancy?\n")
friends.insert(int(len(friends)/2),'nancy')
print('And that girl who is singing is xiaohong.\n')
friends.append('xiaohong')
print('party is over!\n')
friends.pop()
friends.pop()
friends.pop()
friends.pop()
del friends[-1]
del friends[-1]
friends.remove('xiaoming')
print(friends)
输出结果:
2.列表排序
plance = [ 'kunming', 'xihu', 'shanghai', 'beijing', 'chendu']
print(plance)
print('\n')
print(sorted(plance))
print('\n')
print(plance)
print('\n')
print(sorted(plance,reverse=True))
print('\n')
plance.reverse()
print(plance)
plance.reverse()
print(plance)
plance.sort()
print(plance)
输出结果:
相关文章推荐
- Python入门(01) -- 列表简介
- python-列表 字典 集合 元祖 字符串的相关总结练习
- Python入门练习0006:正整数列表L 结尾0的个数
- 【Python】Python入门简介00
- Python入门:列表、字典拆分参数
- python入门(六):列表,元组的使用
- Python入门练习0005:输出最大公约数 & 最小公倍数
- Python简介和入门
- CDays-3 习题二 (字典及文件读取练习)及相关内容解析。Python 基础教程
- 《Python编程从入门到实践》_第三章_列表简介
- Python之路3【第一篇】Python简介入门
- Python简介与入门(基于Python2.7)
- python 列表相关小工具
- python中的List/列表的相关操作
- [Python入门及进阶笔记]Python-基础-数字处理相关模块
- Python入门 [输出,注释,列表,元祖,集合,字典,if,while,for]
- 【Python编程:从入门到实践】第三章:列表简介
- Python入门-操作列表
- Python入门小练习
- Lattice系列FPGA入门相关1(Lattice系列FPGA简介)