python 函数相关
[ 装饰器:]
#!/usr/bin/env/ python
from time import ctime
def tsfunc(func):
~ def wrappedFunc():
~ ~ print '[%s] %s() called' % ( ctime(), func.__name__)
~ ~ return func()
~ return wrappedFunc
@tsfunc
def foo():
~ pass
foo() #=> [Sun Mar 19 22:50:28 2006] foo() called
[ lambda: ]
def usuallyAdd(x,y=2) : return x + y
<=> lambda x,y=2 : x+y
[ global: ]
def foo():
~ bar = 200
~ print bar
bar = 100
print bar #=> 100
foo() #=> 200
print bar #=> 100
def foo2():
~ global bar
~ bar = 300
~ print bar
print bar #=> 100
foo2() #=> 300
print bar #=> 300