Python_C3_变量【下】
来源:互联网 发布:网络红歌大全 编辑:程序博客网 时间:2024/05/05 12:01
3.3.3 通过附加序列增长列表
不能用append方法,它会向列表中添加分层的序列;
可以用extend方法。
>>> living_room=("rug","table","chair","TV","dustbin","shelf")>>> apartment=[]>>> apartment.append(living_room)>>> print(apartment)[('rug', 'table', 'chair', 'TV', 'dustbin', 'shelf')] # 使用append方法,得到的分层序列>>> apartment1=[]>>> apartment1.extend(living_room)>>> print(apartment1)['rug', 'table', 'chair', 'TV', 'dustbin', 'shelf'] #正确结果3.3.4 使用列表临时存储数据
使用pop方法弹出列表中的元素,pop(0)、pop(1)......
>>> todays_temperatures=[23,32,33,31]>>> todays_temperatures.append(29)>>> todays_temperatures[23, 32, 33, 31, 29]>>> morning=todays_temperatures.pop(0)>>> print("This mornings temperature was %0.2f"% morning)This mornings temperature was 23.00>>> late_morning=todays_temperatures.pop(0)>>> late_morning32>>> noon=todays_temperatures.pop(0)>>> noon33>>> todays_temperatures[31, 29]说明:如果不告诉pop要删除列表中的那个元素,则把列表中最后一个删除。
3.3.5 处理集合
集合与字典类似,只是仅包含键,而没有与键相关联的值。
在本质上,集合是不包含重复数据的数据集。
用途之一:可以用于从数据集中删除重复数据。
>>> alphabet=['a','b','c','d','a','f','g','d']>>> alphabet['a', 'b', 'c', 'd', 'a', 'f', 'g', 'd']>>> alph2=set(alphabet) #使用set>>> alph2{'d', 'f', 'g', 'a', 'b', 'c'}
0 0
- Python_C3_变量【下】
- Python_C3_变量【上】
- Python_C3_变量【中】
- Linux 下条件变量
- windows 下时间变量
- 变量延迟(下)
- 多线程下读写vector变量
- Linux下变量的小结
- Hive下的变量使用
- Hive下的变量使用
- Hive下变量的使用
- mysql系统变量(下)
- hive下变量的使用
- linux shell下的变量
- Linux下修改PATH变量
- Linux下的变量替换
- linux 下的path变量
- Linux下将awk的变量赋值给shell变量
- 异地发布
- java推荐书籍
- TRUNCATE,DELETE,DROP区别
- 罐子和硬币-c#求解-英雄会在线编程题目
- 【i黑马】网站运营者之痛:做了三年的网站为何流量还在500IP
- Python_C3_变量【下】
- php单例模式实现日志处理类库
- Privacy Policy for Win8开发-FollowMe
- mysql非主键自增长
- UML概述
- hdu-2167-Pebbles--炮兵布阵之类的 状态压缩dp
- 胡扯IoC(Inversion of Control)
- PHP遍历并打印指定目录下所有文件
- js学习(三)继承