Head First Python——初识Python+列表

来源:互联网 发布:unity3d 材质球shader 编辑:程序博客网 时间:2024/06/05 23:01

Python 是解释型语言

解释型语言就是编译成中间代码程序,在执行时靠翻译程序一起执行,边翻译边执行,当然是靠翻译程序才可以达到跨平台。

编译型就是编译的时候直接编译成机器可以执行的程序,同时也就决定了运行程序所要的平台。

Python 列表

在Python中创建一个列表时,解释器会在内存上创建一个类似数组的数据结构来存储数据,数据项自下而上堆放(形成一个堆栈)。

创建简单的Python列表

>>>movies = ["The Holy Grail","The Life of Brian","The Meaning of Life"]

使用中括号记法访问列表数据

print(movie[1])

print()BIF在屏幕上显示这个列表

len()BIF得出列表中有多少个数据项

列表方法

append() 在列表的末尾添加一个数据项

pop() 从列表末尾删除数据

extend() 在列表末尾添加一个数据项集合

remove() 在列表中找到并删除一个特定的数据项

insert() 在某个特定位置前面增加一个数据项

>>> cast=["Clesse","Palin","Tones","Edle"]>>> cast.append("Gilliam")>>> print(cast)['Clesse', 'Palin', 'Tones', 'Edle', 'Gilliam']>>> cast.pop()'Gilliam'>>> print(cast)['Clesse', 'Palin', 'Tones', 'Edle']>>> cast.extend(["Gilliam","Chapman"])>>> print(cast)['Clesse', 'Palin', 'Tones', 'Edle', 'Gilliam', 'Chapman']>>> cast.remove("Chapman")>>> print(cast)['Clesse', 'Palin', 'Tones', 'Edle', 'Gilliam']>>> cast.insert(0,"Chapman")>>> print(cast)['Chapman', 'Clesse', 'Palin', 'Tones', 'Edle', 'Gilliam']





0 0