Python老男孩 day15 函数(三) 前向引用之'函数即变量'

https://www.cnblogs.com/linhaifeng/articles/6113086.html

——————————————————————————————————————

六、前向引用之'函数即变量'

def foo():
    print('from foo')
    bar()

foo()

运行结果:
NameError: name 'bar' is not defined

def foo():
    print('from foo')
    bar()

def bar():
    print('from bar')
foo()

运行结果:
from foo
from bar

def foo():
    print('from foo')
    bar()

foo()

def bar():
    print('from bar')

运行结果:
NameError: name 'bar' is not defined
from foo

原文地址:https://www.cnblogs.com/zhuhemin/p/9104436.html