数组list操作:
- variable.append( argu ) 在数组的最后一项添加元素
- slice = list[start: end: stride] 截取出从start(包含)到end(不包含)的元素并返回,stride指间隔数. 此函数可用于字符串
- list.insert(index,'content') 在序号前插入指定内容
- list.index('content') 查找'content'的序号
- list.sort() 对数组进行排序,并修改原数组
- list.remove('content') 从数组中移除内容,不返回值
- list.pop(index) 移除序号元素,并返回 index可以是负数,-1为len(list)-1
- del(list[index]) 删除元素 并不返回
- range(start, end, stride) 同slice 创建参数范围内的数组
- '连接符'.join(list) 讲数组按连接符链接,并返回一个字符串
- enumerate 输出数组内容以及对应序列号 一般用于for循环
for index, item in emumerate(list):
Python匿名函数
filter(lambda x: x*x, list) (以后待补充)
字典Dict操作:
字典中key和value相互对应
- dict['key'] = 'value' 对字典进行元素添加
- del dict['key'] 删除字典某个属性
- 若字典内有包含数组 可以用 dict['list'][index]来调用数组元素
- dict.items() 遍历字典,以tuples形式返回key和value
- dict.keys() 返回key
- dict.values() 返回value
网友评论