python第11篇-局部变量

来源:互联网 发布:qq采集软件哪款好用 编辑:程序博客网 时间:2024/06/08 07:01
#!/usr/bin/python#filename func_local.pyx = 50def func(x):    print('x is',x)    x = x + 1    print('changed local x to',x)func(x)print('x is still',x)


结果:

x is 50changed local x to 51x is still 50

虽然全局变量和局部变量同名,但是在函数中的变量时局部变量,作用域也时函数中。

原创粉丝点击