UnboundLocalError: local variable 'checking' referenced before assignment
UnboundLocalError: local variable 'checking' referenced before assignment
我有无法解决的问题。我收到错误
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
将 checking
初始化为 False
作为函数的第一行以避免此错误。
作为函数体的第一行,代码如下:
checking = False
您有一个 return
声明 returns checking
的值,但您的代码并不总是设置它。 Referenced before assignment
表示您的 return
语句在您的代码分配变量之前询问变量的值。
我有无法解决的问题。我收到错误
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
将 checking
初始化为 False
作为函数的第一行以避免此错误。
作为函数体的第一行,代码如下:
checking = False
您有一个 return
声明 returns checking
的值,但您的代码并不总是设置它。 Referenced before assignment
表示您的 return
语句在您的代码分配变量之前询问变量的值。