局部变量
妙舞汉宫人
这个作者很懒,什么都没留下…
展开
-
成员变量和局部变量的区别
(1)在类中的位置不同 成员变量:类中方法外 局部变量:方法定义中或者方法声明上 (2)在内存中的位置不同 成员变量:在堆内存中 局部变量:在栈内存中 (3)生命周期不同 成员变量:随着对象的创建而存在,随着对象的消失而消失 局部变量:随着方法的调用而存在,随着方法的调用完毕而消失转载 2016-01-03 14:29:46 · 296 阅读 · 0 评论 -
变量的作用域
def func(x): print 'X in the beginning of func(x): ', x x = 2 #局部变量 print 'X in the end of func(x): ', x x = 50 func(x) print 'X after calling func(x): ', x #X in the beginning of func(x): 5转载 2016-08-11 10:55:03 · 218 阅读 · 0 评论