对于局部变量和全局变量python中跟php是一样的。
php:
python:
php:
- <?php
- function x() {
- global $x;
- echo $x.'<br>';
- $x=3;
- echo 'change x value '.$x.'<br>';
- }
- $x=1;
- x();
- echo 'x is '.$x;
- ?>
- def func():
- global x
- print 'x is',x
- x=3
- print 'change local x to ',x
- x=1
- func()
- print 'value of x is ',x