Python 什么是';赋值前引用的局部变量';
我正在尝试解决checkio(房屋密码)的一个问题 …我的代码如下Python 什么是';赋值前引用的局部变量';,python,python-3.x,error-handling,Python,Python 3.x,Error Handling,我正在尝试解决checkio(房屋密码)的一个问题 …我的代码如下 def checkio(data): if len(data)>9: for i in data: if str.isdigit(i)==True: global counternumber counternumber=counternumber+1 if str.isupper(i)==
def checkio(data):
if len(data)>9:
for i in data:
if str.isdigit(i)==True:
global counternumber
counternumber=counternumber+1
if str.isupper(i)==True:
global counterupper
counterupper=counterupper+1
if str.islower(i)==True:
global counterlower
counterlower=counterlower+1
if (counternumber>1 & counterupper>1 & counterlower>1):
return True
else:
return False
在尝试实现此功能时,会弹出以下错误
NameError:未定义全局名称“counterupper”
在声明为全局变量之前,会弹出错误
UnboundLocalError: local variable 'counterupper' referenced before assignment,
这些错误意味着什么?如何解决它们
请解释清楚,因为我是编程新手。您可以简而言之:
def checkio(data):
return (len(data) > 9 and
any(ch.isdigit() for ch in data) and
any(ch.isupper() for ch in data) and
any(ch.islower() for ch in data))
你不是真的在找,是吗?