http://blog.csdn.net/yasi_xi/article/details/38384047.html
来源:互联网 发布:ospf spf算法 编辑:程序博客网 时间:2024/05/22 13:28
Python中,有3种内建的数据结构:列表、元组和字典。
1.列表
实例:
#coding=utf-8
animalslist=['fox','tiger','rabbit','snake']
print "I don't like these",len(animalslist),'animals...'
for items in animalslist:
#对列表的操作,添加,删除,排序
animalslist.append('pig')
del animalslist[0]
animalslist.sort()
for i in range(0,len(animalslist)):
结果:
I don't like these 4 animals...
fox tiger rabbit snake
操作后
pig rabbit snake tiger
2.元组
>>> zoo=('wolf','elephant','penguin')
>>> zoo.count('penguin')
1
>>> zoo.index('penguin')
2
>>> zoo.append('pig')
Traceback (most recent call last):
AttributeError: 'tuple' object has no attribute 'append'
>>> del zoo[0]
Traceback (most recent call last):
TypeError: 'tuple' object doesn't support item deletion
3 字典
字典类似于你通过联系人名称查找地址和联系人详细情况的地址簿,即,我们把键(名字)和值(详细情况)联系在一起。注意,键必须是唯一的,就像如果有两个人恰巧同名的话,你无法找到正确的信息。
实例:
#coding=utf-8
dict1={'zhang':'张家辉','wang':'王宝强','li':'李冰冰','zhao':'赵薇'}
#字典的操作,添加,删除,打印
dict1['huang']='黄家驹'
del dict1['zhao']
for firstname,name in dict1.items():
结果:
li 李冰冰
wang 王宝强
huang 黄家驹
zhang 张家辉
阅读全文
0 0
- http://blog.csdn.net/yasi_xi/article/details/38384047.html
- PTHREAD_MUTEX_INITIALIZER http://blog.csdn.net/yasi_xi/article/details/19197203
- Java程序和C程序的相互调用http://blog.csdn.net/yasi_xi/article/details/8437628
- Android与HTML+JS交互入门http://blog.csdn.net/leejizhou/article/details/50894531
- http://blog.csdn.net/IBM_hoojo/article/details/5688947
- http://blog.csdn.net/chenlaic/article/details/6143235
- http://blog.csdn.net/eaglewood2005/article/details/4335052
- http://blog.csdn.net/mchp/article/details/3995970
- http://blog.csdn.net/v_july_v/article/details/6015165
- http://blog.csdn.net/masterz/article/details/6232585
- http://blog.csdn.net/perfectpdl/article/details/6442847
- http://blog.csdn.net/eroswang/article/details/1967243
- http://blog.csdn.net/zhvsby/article/details/5986645
- http://blog.csdn.net/dz45693/article/details/6183645
- http://blog.csdn.net/david_lv/article/details/5798003
- http://blog.csdn.net/zxingchao2009/article/details/6299313
- http://blog.csdn.net/zhanxinhang/article/details/6783766
- http://blog.csdn.net/ruanruoshi/article/details/935510
- 448. Find All Numbers Disappeared in an Array
- 使用Scalatra创建Scala WEB工程
- OpenCV库的部分配置
- Android 构建者模式(Builder)
- SAP 供应商关系管理
- http://blog.csdn.net/yasi_xi/article/details/38384047.html
- 卓有成效的管理者(笔记)——我能贡献什么
- 算法题/将一个字符串转换成数字
- 所有iOS设备的屏幕尺寸
- 第十四篇:JAVA之集合框架
- 371. Sum of Two Integers
- SQL中的join连接查询(left join/right join/inner join)
- 一个简单的html抽奖
- 父子进程通过管道实现文件复制