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

 

posted @ 2018-05-29 12:32  小飞侠Kobe  阅读(455)  评论(0编辑  收藏  举报