即函数调用在函数定义之前
可以这样
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
时间: 2024-10-27 13:08:07