码迷,mamicode.com
首页 > 编程语言 > 详细

python 前向引用

时间:2016-12-03 15:11:34      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:call   ast   efi   pycha   函数   name   trace   erro   err   

 即函数调用在函数定义之前

 

可以这样

def bbb():
    print(‘this is b‘)
    aaa()
def aaa():
    print(‘this is a‘)
bbb()
--------->
this is b
this is a

可以这样

def aaa():
    print(‘this is a‘)
def bbb():
    print(‘this is b‘)
    aaa()
bbb()
----------->
this is b
this is a

但不可以这样

def bbb():
    print(‘this is b‘)
    aaa()
bbb()
def aaa():
    print(‘this is a‘)
--------->
Traceback (most recent call last):
this is b
  File "E:/pycharm/TEST.py", line 600, in <module>
    bbb()
  File "E:/pycharm/TEST.py", line 599, in bbb
    aaa()
NameError: name ‘aaa‘ is not defined

  

python 前向引用

标签:call   ast   efi   pycha   函数   name   trace   erro   err   

原文地址:http://www.cnblogs.com/lcgsmile/p/6128597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!