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

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

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

猜你喜欢

转载自www.cnblogs.com/zhuhemin/p/9104436.html
今日推荐