函数定义 在 函数调用 之前

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

就如同变量的定义一般

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

  

相关文章:

  • 2021-09-21
  • 2021-12-18
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
猜你喜欢
  • 2021-11-19
  • 2021-11-14
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
相关资源
相似解决方案