python的UnboundLocalError: local variable 'xxx' referenced before assignment
来源:互联网 发布:淘宝买单反相机可靠吗 编辑:程序博客网 时间:2024/05/01 07:08
From: http://blog.sina.com.cn/s/blog_8d3652760101d01p.html
一、意思:
二、错误原因
三、产生这个错误的场景
参考资料:http://www.uplook.cn/biancheng/107/1078875/python代码:
val=9
deftest(flag):
if flag:
val = 1
else:
print 'fuck'
return val
test(0)
错误提示:UnboundLocalError: local variable 'val' referenced before assignment
解决方法:用global关键字来进行说明该变量是全局变量
python代码:
val=9
def test(flag):
global val
if flag:
val = 1
else:
print 'test'
return val
test(0)
val=9
def
test(0)
错误提示:UnboundLocalError: local variable 'val' referenced before assignment
解决方法:用global关键字来进行说明该变量是全局变量
python代码:
val=9
def test(flag):
test(0)
0 0
- python的UnboundLocalError: local variable 'xxx' referenced before assignment
- python的UnboundLocalError: local variable 'xxx' referenced before assignment
- Python的UnboundLocalError: local variable 'xxx' referenced before assignment
- Python的UnboundLocalError: local variable 'xxx' referenced before assignment
- UnboundLocalError: local variable 'XXX' referenced before assignment
- Python - UnboundLocalError: local variable referenced before assignment
- 错误:UnboundLocalError: local variable 'xxx' referenced before assignment
- 【Python】UnboundLocalError: local variable 'l' referenced before assignment
- 【Python基础】之全局变量(UnboundLocalError: local variable referenced before assignment)
- 【Python】UnboundLocalError: local variable 'l' referenced before assignment
- 【python】UnboundLocalError: local variable 'counter' referenced before assignment
- python:UnboundLocalError: local variable 'l' referenced before assignment
- 【Python】UnboundLocalError: local variable 'x' referenced before assignment
- 【Python基础】Python3: UnboundLocalError: local variable 'num' referenced before assignment
- 【Python异常】UnboundLocalError: local variable 'xxxx' referenced before assignment
- UnboundLocalError: local variable 'l' referenced before assignment
- UnboundLocalError: local variable 'l' referenced before assignment
- UnboundLocalError: local variable ' ' referenced before assignment
- jQuery选择器类型
- 各种数据类型与C#数据类型对照关系
- 发一条短信路程简介
- android中获取当前activity的名称
- 在项目里交叉使用Swift和OC
- python的UnboundLocalError: local variable 'xxx' referenced before assignment
- vim的保存文件和退出命令
- OCP 1Z0 052 V9.02 116
- 对比Fibonacci两种算法效率
- BZOJ 1626: [Usaco2007 Dec]Building Roads 修建道路
- 通讯录二维码使英文变为中文
- spring部分源码分析
- 类名.class.getName()
- OCP-1Z0-051-题目解析-第13题