您的位置:首页 > 编程语言 > Python开发

python列表操作使用示例分享

2014-02-21 15:31 751 查看
Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:13:51) [MSC v.1600 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>>> cast=["cleese","palin","jones","idle"]>>> print(cast)['cleese', 'palin', 'jones', 'idle']>>> print(len(cast))#显示数据项数量4>>> print(cast[1])#显示列表中第2个数据项的值palin>>> cast.append("gilliam")#在列表末尾添加一个数据项>>> print(cast)['cleese', 'palin', 'jones', 'idle', 'gilliam']>>> cast.pop()#删除列表末尾的数据项'gilliam'>>> print(cast)['cleese', 'palin', 'jones', 'idle']>>> cast.extend(["gilliam","chapman"])#在列表末尾增加一个数据项集合>>> print(cast)['cleese', 'palin', 'jones', 'idle', 'gilliam', 'chapman']>>> cast.remove("chapman")#删除指定的数据项>>> print(cast)['cleese', 'palin', 'jones', 'idle', 'gilliam']>>> cast.insert(0,"chapman")#在指定的位置增加数据项>>> print(cast)['chapman', 'cleese', 'palin', 'jones', 'idle', 'gilliam']>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 列表