python 基础数据结构学习
字符串
字符串里有三个去空格、特殊字符的函数
strip 同时去掉左右两边的空格
lstrip 去掉左边的空格
rstrip 去掉右边的空格
x.strip('[')
字符串按照,分隔转换成列表
items = item.split(',')
sStr1 = 'strchr'
sStr2 = 'r'
nPos = sStr1.index(sStr2)
sStr1 = 'strchr' sStr2 = 'strch' print cmp(sStr1,sStr2)
sStr1 = '12345678' sStr2 = '456' print len(sStr1 and sStr2)http://www.pythonclub.org/python-basic/string
字典
字典key值不可以为列表 可将列表转换成字符串str = ''.join(list) 字典的key值必须唯一,否则后者会覆盖前者
取得所有key值 value 值
dict.keys() dict.values()
字典定义 dict={} 添加项目dict['a']='b' key 和 value都可以为control
字典方法介绍很全
http://wiki.shine-it.net/index.php?title=%E5%BC%80%E5%A7%8BPython--Dictionary&variant=zhhttp://wiki.shine-it.net/index.php?title=%E5%BC%80%E5%A7%8BPython--Dictionary&variant=zh
列表
创建列表
sample_list = []
删除列表
del sample_list[-1]
在指定位置插值
sample_list[0:0] = ['sample value']
列表切片
sample_list[0:3] 不包含3