码迷,mamicode.com
首页 > 其他好文 > 详细

前向引用

时间:2017-06-03 21:50:04      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:error:   mos   char   --   err   lin   cal   this   mod   

函数定义 在 函数调用 之前

而函数定义的顺序无关紧要

就如同变量的定义一般

a = 1
b = 2

#两者没什么不同

b = 2
a = 1

  例

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

  

前向引用

标签:error:   mos   char   --   err   lin   cal   this   mod   

原文地址:http://www.cnblogs.com/freelandun/p/6938439.html

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