UnboundLocalError:在assignmen之前引用了局部变量“checking”

2024-05-19 13:08:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个无法解决的问题。我知道错误了

UnboundLocalError: local variable 'checking' referenced before assignment

我的代码

    def volume_checker_first_stage(volume1,volume2,withdraw_minimun):
      if volume1>volume2:
       quantity = volume2
       if quantity > withdraw_minimun:
            checking = True
       return quantity, checking
      elif volume2>volume1:
       quantity = volume1
       if quantity > withdraw_minimun:
              checking = True
       return quantity, checking
      else:
       return None,None

Tags: nonetruereturniflocal错误variablequantity
2条回答

checking初始化为False作为函数中的第一行,以避免此错误。在

作为函数主体的第一行,请编写以下代码:

checking = False

您有一个返回return值的return语句,但您的代码并不总是设置它。Referenced before assignment表示您的return语句在代码分配变量之前请求它的值。在

相关问题 更多 >