Skip to content

Commit c44329d

Browse files
committed
add lambda and enchance modal
1 parent 3806058 commit c44329d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

function.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,9 @@ def printMax(x, y):
9696
print y, 'is maximum'
9797

9898
printMax(3, 5)
99-
print printMax.__doc__
99+
print printMax.__doc__
100+
101+
# lamda 匿名函数,有点类似闭包
102+
print 10 * '*', 'lambda', 10 * '*';
103+
print (lambda a,b: a+b)(1,3); #4
104+
print map(lambda x: x * x, [1,2,3]); # [1, 4, 9]

module.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python
2+
#coding:utf-8
3+
4+
import sys
5+
6+
print 'The command line arguments are:'
7+
for i in sys.argv:
8+
print i
9+
10+
print '\n\nThe PYTHONPATH is', sys.path, '\n'
11+
12+
# from..import语句
13+
14+
# 如果你想要直接输入argv变量到你的程序中(避免在每次使用它时打sys.),那么你可以使用from sys import argv语句。如果你想要输入所有sys模块使用的名字,那么你可以使用from sys import *语句。这对于所有模块都适用。
15+
# 注意:一般说来,应该避免使用from..import而使用import语句,因为这样可以使你的程序更加易读,也可以避免名称的冲突。
16+
17+
18+
# 每个模块都有一个名称,在模块中可以通过语句来找出模块的名称。
19+
# 这在一个场合特别有用——就如前面所提到的,当一个模块被第一次输入的时候,这个模块的主块将被运行。假如我们只想在程序本身被使用的时候运行主块,而在它被别的模块输入的时候不运行主块,我们该怎么做呢?这可以通过模块的__name__属性完成。
20+
if __name__ == '__main__':
21+
print 'This program is being run by itself'
22+
else:
23+
print 'I am being imported from another module'
24+
25+
# 更多关于包的介绍
26+
# http://sebug.net/paper/books/python_hb/node8.html#SECTION008110000000000000000

number.python renamed to number.py

File renamed without changes.

0 commit comments

Comments
 (0)