函数特点

#def定义的非匿名函数,不会被立即回收
'''
def foo():
print("in the foo")
bar() #foo调用的时候,还未被被定义,所以报错

foo()
'''
def bar():
print("in the bar")

def foo():
print("in the foo")
bar() #已经被定义,所以不报错
foo()

#匿名函数,内存立即回收
calc = lambda x:x*3
calc(3) #等于9

猜你喜欢

转载自www.cnblogs.com/wzsx/p/9077226.html