易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : Python

Python入门的36个例子——04 优雅的字符串

# 004
# 利用三引号(''' or """)可以指示多行字符串
print '''line1
line2
line3'''
# 另外,你还可以在三引号中任意使用单引号和双引号
print ''' "What's up? ," he replied.'''
# 否则,你好使用转义符来实现同样的效果
# 还是使用三引号好,不然就破坏了视觉美了
print ' \"What\'s up? ,\" he replied.'
# 你可以使用raw(r)(原始字符串)来消除转义字符的转义功能
print r' \"What\'s up? ,\" he replied.'
# 单引号和双引号的全等性似乎意味着Python中没有“char”这个概念
# 事实正是如此!
# “char”是为机器服务的(The genesis of the computer revolution was in a machine. The genesis of our programming languages thus tends to look like that machine.)
# 而Python是为程序员服务的

output:
1
2
3
4
5
6
line1
line2
line3
 "What's up? ," he replied.
 "What's up? ," he replied.
 \"What\'s up? ,\" he replied.
......

Python入门的36个例子——05 聪明的变量

# 005
# 在Python中给变量赋值时不需要声明数据类型
i = 33
print i
# 可以这样做的原因是Python把程序中遇到的任何东西都看成是对象(连int也不例外)
# 这样,在使用对象时,编译器会根据上下文的环境来调用对象自身的方法完成隐式的转换
# 你甚至可以把程序写成这样
print 3 * 'haha '
# 但若写成这样编译器就会报错(注意3后面的点)
# print 3. * 'haha'

output:
1
2
33
haha haha haha
......

Python入门的36个例子——15 默认参数

# 015
# 默认参数的本质是:
# 不论你是否提供给我这个参数,我都是要用它,
# 那么我就要想好在你不向我提供参数的时候我该使用什么。
# 或者,这样来理解:
# 有一些参数在一般情况下是约定俗成的,
# 但,在极少情况下会有一些很有个性的人会打破传统而按照自己的习惯来做事
def theFirstDayInAWeek(theDay = 'Sunday'):
print theDay
# end of def
theFirstDayInAWeek()
theFirstDayInAWeek('Monday')
# 注意:
# 只有在形参表末尾的那些参数可以有默认参数值
# 例如:def func(a, b=5)是有效的,但是def func(a=5, b)是无效的

output:
1
2
Sunday
Monday
......

Python入门的36个例子——17 Return

# 017
def lifeIsAMirror():
string = raw_input()
if string == 'I love you!':
return 'I love you, too!'
elif string == 'Fuck you!':
return ''
else:
return
# end of def
string = lifeIsAMirror()
if len(string) == 0:
print 'You have nothing.'
else:
print string
# end of if

output:
1
2
3
4
5
6
>>>
Fuck you!
You have nothing.
>>>
I love you!
I love you, too!
......

Python:FriendFeed的Tornado Web Server

代码很简单,不到5k行。但是思路挺好的,改成non-blocking了之后效率就是能提高不少,特别是考虑到现代的web app都需要和其他的
HTTP服务器通信,blocking的代价太大了。 Tornado is an open source version of the scalable, non-blocking web server and tools that power FriendFeed. The FriendFeed application is written using a web framework that looks a bit like web.py or Google's webapp, but with additional tools and optimizations to take advantage of the underlying non-blocking infrastructure.
The framework is distinct from most mainstream web server frameworks (and certainly most Python frameworks) because it is non-blocking and reasonably fast. Because it is non-blocking and uses epoll, it can handle thousands of simultaneous standing connections, which means it is ideal for real-time web services. We built the web server specifically to handle FriendFeed's real-time features — every active user of FriendFeed maintains an open connection to the FriendFeed servers. (For more inform ......

学习《Python语言入门》第五章 模块

模块这东西好像没什么好讲的,无非是保存一份文件,然后在另一份文件中用import 和from ** import **(*)就行了。
这一章主要讲到了细节,导入模块Python里面是什么处理的,import 和 from ** import **有什么不一样。还有就是增加了reload()这个函数的使用说明。
以前看到哪里说尽量使用import而不要使用from ** import **,一直不知道原因,在这一章里找到了答案。其实就是Python导入模块时引用和赋值的区别。后面的模块常见问题也从这里展开。
模块设计估计是很有难度的东西,可惜这里讲得太少了,只提出了4个原则,没有实际的例子。
下一章的类是个大头,已经在看了。作者用了不少篇幅写类。 ......
总记录数:695; 总页数:116; 每页6 条; 首页 上一页 [104] [105] [106] [107] 108 [109] [110] [111] [112] [113]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号