-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_lambda.py
More file actions
54 lines (39 loc) · 918 Bytes
/
Copy pathtest_lambda.py
File metadata and controls
54 lines (39 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
#!coding:utf-8
import functools
'''函数'''
#匿名函数
print map(lambda x: x * x,[1,2,3,4,5])
#匿名函数转换成一般函数
def Test(x):
return x * x
print [Test(x) for x in range(3)]
#不带参数装饰器(decorator)
print '不带参数装饰器'
def log(func):
@functools.wraps(func)
def wrapper(*args,**kw):
print 'call %s()' % func.__name__
return func(*args,**kw)
return wrapper
@log
def now():
print 'now is today'
print now.__name__
now()
def log2(text):
def decorator(func):
@functools.wraps(func)
def wrapper(*args,**kw):
print '%s %s()' % (text,func.__name__)
return func(*args,**kw)
return wrapper
return decorator
@log2('hello')
def now2():
print 'now2 today'
now2()
print '偏函数'
print int('22',base=16)
int2 = functools.partial(int,base=2)
print int2('100000')