python - Python = 在 DEF 中
问题描述
代码:
print("Starting...")
def test():
notare = input()
bote()
def bote():
if notare == "a":
print("b")
else:
print("c")
test()
错误:
Traceback (most recent call last):
File "test.py", line 13, in <module>
test()
File "test.py", line 5, in test
bote()
File "test.py", line 8, in bote
if notare == "a":
NameError: name 'notare' is not defined
解决方案
python 不会知道该函数存在... Python 以有序的方式执行... 这意味着您必须先声明该函数,然后才能调用它...
所以对于你的问题..尝试将函数移到调用它的函数之上..
像这样
print("Starting...")
def bote(notare):
if notare == "a":
print("b")
else:
print("c")
def test():
notare = input()
bote(notare)
test()
推荐阅读
- amazon-web-services - 将 AWS SES 与电子邮件正文的第三方加密结合使用有哪些可用选项?
- service-worker - 第二个更新服务人员不起作用
- java - maven:是否包含间接依赖?
- python - sklearn:在 MaskedArray 上预测的分类器
- spring - 为什么我不能使用 Spring Data Jdbc 插入实体两次?
- java - 用于检查调试/跟踪日志记录级别的 SonarQube Java 规则
- xstate - 如何使用 xstate 建模多个页面
- java - Pass function as parameter to Lambda java 8
- flutter - 在flutter中登录应用程序期间加载主屏幕时的CircularprogressIndicator
- assembly - 负值作为结果汇编