|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def next():
print('我在next()函数里...')
pre()
def pre():
print('我在pre()函数里...')
next()
这是题目,问会输出什么?以下是答案。
有些编程语言不够“聪明”,向这类向前引用的方式会导致报错,但Python足够“醒目”,这段代码是正确的!
会输出:
我在next()函数里...
我在pre()函数里...
问题是我复制代码后只输出了第一行,后面报错了,不知道什么原因??请教高手
我在next()函数里...
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
next()
File "<pyshell#2>", line 3, in next
pre()
UnboundLocalError: local variable 'pre' referenced before assignment
你复制错了吧,亲测没问题啊,
- def next():
- print('我在next()函数里...')
- pre()
- def pre():
- print('我在pre()函数里...')
-
- next()
复制代码
输出:
- 我在next()函数里...
- 我在pre()函数里...
复制代码
你看看你上面哪里引用了pre,在赋值前,造成报错
|
|