Python数据结构之——list
Python中有四种内建的数据结构:List,Tuple,Dictionary,Set。本文主要介绍List。
List是用来存放一组对象序列。可以像list中添加元素、删除元素,同时也可以像访问数组一样访问list。List是可变的数据类型。
下面,给出一组list的使用实例:
shoplist = ['rice','apple','banana','mango']
print('I hava ',len(shoplist),' items to purchase')
print('These items are:',end=' ')
for item in shoplist:
print(item,end=' ')
print('\nI also have to buy carrot')
shoplist.append('carrot')
print('My shoplist now is: ',shoplist)
shoplist.sort()
print('My shoplist after sorted is: ',shoplist)
del shoplist[1]
print('My shoplist after del is: ',shoplist)
shoplist.reverse()
print('My shoplist after reversed is: ',shoplist)
shoplist.remove('rice')
print('My shoplist after remove is: ',shoplist)
首先,可以使用“[]”来创建一个list,并可以直接对其进行初始化;可以使用for..in语法来迭代访问list;可以使用append方法来向list中添加元素;可以使用remove方法从list中移除元素;可以使用del来从list中删除指定索引的元素;可以使用sort方法来对list进行正序的排序,在这里,需要注意的是该方法不返回值,而是直接改变list本身;可以使用reverse方法来倒置list中的元素。
关于list的进一步使用,可以使用help(list)来查看。
相关文档:
先将上面创建好的testdemo工程目录\,将C:\Python25\Lib\site-packages\django\bin中的testdemo目录拷贝到自己的工作目录中,然后启动eclipse,点击“File”->“New”->“project…”,将会看到以下画面
选择“Pydev Project”,点击“Next&rdquo ......
作者:老王
Python似乎很讨厌修饰符,没有常见的static语法。其静态方法的实现大致有以下两种方法:
第一种方式(staticmethod):
>>> class Foo:
str = "I'm a static method."
def ba ......
from http://blog.alexa-pro.cn/?p=315
此文档使用平台为 cPAMIE Build 2.0,和之前的版本有明显的差别,具体可直接看cPAMIE.py 源码
下面是一些常用的方法
ie.navigate('http://blog.alexa.cn') 用来访问一个链接。
ie.linkClick('linkname') 打开这个页面中的一个连接 参数: name或 id
ie.textBoxSet('labels','python ......
from http://stackoverflow.com/questions/101268/hidden-features-of-python
http://www.okpython.com/bbs/thread-3434-1-1.html
http://www.okpython.com/bbs/thread-3436-1-2.html
http://www.okpython.com/bbs/thread-3437-1-2.html
http://www.okpython.com/bbs/thread-3438-1-1.html
http://www.okpython.com/bb ......
网络臭虫亦即网络信标,是通过某种手段隐式获取信息的的方法。
在bottle framework中可用下面的方法实现:
首先在你要用户浏览器显示的页面tpl上嵌入一个1*1像素的图片,或更小。
这个图片地址指向你服务器上某个特定位置,如static/webtrack.png。
用户打开网页,就会访问这个图片(通过浏览器如http://abc.abc.com/st ......