python 全局变量规则
2017-11-18 12:39
225 查看
Section 1
mValue = "1" def fun1(): if(mValue=="1"): print(mValue)运行正常Section 2
def fun2(): if(mValue=="1"): mValue = "hah"; print(mValue)IDE检测不过Section 3
def fun2(): global mValue; if(mValue=="1"): mValue = "hah"; print(mValue)
运行正常
总结: (1)在方法中可以直接打印全局变量
(2)在方法中修改全局变量的值需要先global申明====================================================补充:可变类型的全局变量不使用global也可以修改
相关文章推荐
- Python7--局部变量、全局变量、缺省参数、不定长参数、递归
- Python标识符规则、关键字、特殊变量操作实例
- [ROBOT] python library 如何能获取到ROBOT框架里面的全局变量,例如${OUTPUT DIR}等
- Python实现全局变量的两个解决方法
- Python module中的全局变量
- Python实现全局变量的两个解决方法
- python中全局变量
- Python学习入门基础教程(learning Python)--2.2.2 Python全局和局部变量 .
- Python语法基础——关于全局变量与局部变量
- 打印出python 当前全局变量和入口参数的所有属性
- python 变量 命名规则
- python全局变量警告
- python全局变量-局部变量用法和区别
- Python 中模块间全局变量的使用上的注意
- 从局部变量和全局变量开始全面解析Python中变量的作用域
- Python的全局变量和局部变量
- python使用全局变量(global)
- Python----变量与全局变量
- 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment 分类: divide into python python基础学习 问题总结 2014-01-01 16:35 4595人阅读 评论(0)
- python 全局变量