python (),[],{}也即tuple,list,set的区别

一、tupleblog

p1 = ('1','2',3)

遍历方法(索引遍历或者for in两种都可):索引

print "p1[1]", p1[1]
for p in p1:
    print p

结果:遍历

二、list方法

p2 = ['1','2',3]

遍历方法(索引遍历或者for in两种都可):im

print "p2[1]", p2[1]
for p in p2:
    print p

结果:img

三、setco

p3 = {'1','2',3}

遍历方法(for in):ps

for p in p3:
    print p

结果:index

注:set不支持利用index遍历的方法

相关文章
相关标签/搜索