一、注意你的Python版本
Python官方网站为http:///wewe39/item/c2599557739ec9dcd48bacf6list.insert(i,x) 在给定的位置上插入项list.remove(x) 移除列表中的第一个值为x的项,注意x并非索引list.pop([i]) 删除给定位置的项并返回list.index(x) 返回列表中第一个值为x的项索引值,没有匹配项则产生一个错误list.count(x) 返回列表中x出现的次数list.sort() 排序list.reserve() 倒序
遍历示例:
numbers=[0,1,2,3,4,5,6,7,8,9]for i in range(len(numbers)):print(i)2、元组 Tuple
声明方式比较特殊:
tuple=item1,item2,item3例:
tuple=12,323.0,0.34,'Hello'for i in range(len(tuple)):#遍历print(tuple[i])3、集合 Set
声明方式:
set={item1,item2,item3}例:
basket={'a','b','a','c','c','d'}集合为无序不重复的元素集,上例声明的结果将为
{'d', 'a', 'b', 'c'}
遍历方式:
basket={'a','b','a','c','c','d'}for i in basket:print(i)4、字典 Dict
声明示例:
tel={'jack':23423,'sape':234}可使用下述方式进行赋值:
tel['guido']=4127结果为:
{'sape': 234, 'guido': 4127, 'jack': 23423}可使用items()方法取得键和对应的值,例:
for k,v in tel.items():print(k,v)遍历方式:
tel={'jack':23423,'sape':234}for key in tel:print(key ,':' , tel[key])这篇文章就介绍到这了,具体的大家可以看下以前发布的文章。