Amusing Python 2: range/xrange
这两个基本上都是在循环的时候用。
Python
代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i%20in%20range(0%2C%20100)%3A%0A%20%20%20%20print%20i" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14">
for
i
in
range
(
0
,
100
):
print
i
for i in range
(0, 100):
print i
Python
代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i%20in%20xrange(0%2C%20100)%3A%0A%20%20%20%20print%20i" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="15" width="14">
for
i
in
xrange(
0
,
100
):
print
i
for i in xrange(0, 100):
print i
这两个输出的结果都是
一样的,实际上有很多不同,range
会直接生成一个list对象:
Python
代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=%3E%3E%3E%20a%20%3D%20range(0%2C%2010)%0A%3E%3E%3E%20type(a)%0A%3Ctype%20'list'%3E%0A%3E%3E%3E%20a%0A%5B0%2C%201%2C%202%2C%203%2C%204%2C%205%2C%206%2C%207%2C%208%2C%209%5D%0A%3E%3E%3E%20a%5B0%5D%0A0" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/g
相关文档:
测试网站:Baidu主页以及相关的页面
主题:黑盒测试,功能测试,性能/压力测试,安全测试, 数据字典管理
1. 测试页面是否可访问的;
1.1 HTTP request status = 200, 页面下载正确
from urllib import urlopen
# set up
url = None
# test
url = urlopen('http://www.baidu.com')
assert url.getcode() == 200
# ......
Example 2-18 展示了 traceback 模块允许你在程序里打印异常的跟踪返回
(Traceback)信息, 类似未捕获异常时解释器所做的. 如 Example 2-18 所示. 2.11.0.1. Example
2-18. 使用 traceback 模块打印跟踪返回信息 File: traceback-example-1.py # note!
import
Example 2-18 展示了 traceback 模块允许你在程序里打印异常 ......
Python 序列
列表、元组和字符串都是序列,但是序列是什么,它们为什么如此特别呢?序列的两个主要特点是索引操作符和切片操作符。索引操作符让我们可以从序列中抓取一个特定项目。切片操作符让我们能够获取序列的一个切片,即一部分序列。
使用序列
例9.5 使用序列
#!/usr/bin/python
# Filename: seq.py
shoplist ......
Python 用下划线作为变量前缀和后缀指定特殊变量。
_xxx
不能用'from module import *'导入
__xxx__ 系统定义名字
__xxx
类中的私有变量名
核心风格:避免用下划线作为变量名的开始。
因为下划线对解释器有特殊的意义,而且是内建标识符所使用的符号,我们建议程序 ......
第一步:搭建手机运行平台
要在S60手机上运行PY开发的软件,首先就要搭建手机PY运行环境.诺基亚手机本身不支持Python,所以要安装Python插件.
PS:一定要安装在C盘!我一开始装E,结果出现了很严重的问题!不过,最近网上发现有E盘版的啦,你可以自己试验一下,哈哈
PythonScriptShell_1_4_5_3rdEd.SIS
Pyth ......