Python全局变量
2016-05-10 16:12
537 查看
x = 0 y = 0 def incr(x): y = x + 1 return y incr(5) print x, y 全局变量,x,y不会影响到函数中的变量,但是我们可以在函数中使用全局变量 pi = 3.14 def area(r): return pi * r * r
使用global
numcalls = 0 def square(x): global numcalls numcalls = numcalls + 1 return x * x
相关文章推荐
- [python网络编程]使用scapy修改源IP发送请求
- python automated headers 自动生成格式化 注释文件 docstrings
- thrift系列 - 多语言实例 for java和python
- [LeetCode]题解(python):149-Max Points on a Line
- 《统计学习方法》-逻辑回归笔记和python源码
- [LeetCode]题解(python):148-Sort List
- Python介绍
- Python内建的对象列表
- [LeetCode]题解(python):147-Insertion Sort List
- [LeetCode]题解(python):146-LRU Cache
- Python处理Excel(四):自定义类处理Excel数据
- python面向对象编程基础II(类的继承)
- Python基础篇【第8篇】: Socket编程(二)SocketServer
- Python实现欧拉计划22题
- python 多个关键字替换
- 102. Binary Tree Level Order Traversal [easy] (Python)
- Python详说正则表达式(对常用的关键字符的讲解)
- Python学习笔记:集合(set)基本内容
- [LINK]用Python计算昨天、今天和明天的日期时间
- [LINK]python中的日期和时间格式化输出