python列表

来源:互联网 发布:js 模块化框架 编辑:程序博客网 时间:2024/06/05 07:34


# -*- coding:UTF-8 -*-'''Created on 2015年10月25日@author: young'''list=[1,'abc']list.append(1)list.append(['lmn','xyz'] )list.extend([9,10])print listprint list.count('abc')list.reverse()print listprint list.index('abc' )print list.pop()print listlist.remove('abc')print listlist.sort()print listlist.insert( 1, ('a','b','c') ) #插入 元组print listprint '###for each###'for ele in list:    print eleprint '###下标访问###'print list[1]#下标访问    print list[1:-1] #第二到倒数第一个print '元组'tt=( ('a',1) , ('b','b') ,(3,'c')  )print ttfor ele in tt:    print elefor (x,y) in tt:    print x,',', y

打印如下

[1, 'abc', 1, ['lmn', 'xyz'], 9, 10]1[10, 9, ['lmn', 'xyz'], 1, 'abc', 1]41[10, 9, ['lmn', 'xyz'], 1, 'abc'][10, 9, ['lmn', 'xyz'], 1][1, 9, 10, ['lmn', 'xyz']][1, ('a', 'b', 'c'), 9, 10, ['lmn', 'xyz']]###for each###1('a', 'b', 'c')910['lmn', 'xyz']###下标访问###('a', 'b', 'c')[('a', 'b', 'c'), 9, 10]元组(('a', 1), ('b', 'b'), (3, 'c'))('a', 1)('b', 'b')(3, 'c')a , 1b , b3 , c


0 0