| ???? Python ??? | ??7?? ???? | |
|---|---|---|
| ???? | ??????? | ???? |
?????????????????????????????????????????????????????????????¦Ê¦É????????????????????????? ??? ????????????? ?????? ?????§Ò???????????????????????ï…???????????????????????
#!/usr/bin/python
# Filename: func_local.py
def func(x):
print 'x is', x
x = 2
print 'Changed local x to', x
x = 50
func(x)
print 'x is still', x
????????code/func_local.py??
$ python func_local.py
x is 50
Changed local x to 2
x is still 50
??????§µ????????????x?? ? ?????Python??¨²??????????¦Â¦Å????
??????????????2????x??x???????????????????????????????????x???????????????§Ø????x???????
????????print????§µ???????????????§Ö?x??????????????
??????????????????????????????????????????Python?????????????????????? ??? ??????????global?????????????????global????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????t??????????????????????¨®?????????????????????????????????global???????????????????????????úE????
#!/usr/bin/python
# Filename: func_global.py
def func():
global x
print 'x is', x
x = 2
print 'Changed local x to', x
x = 50
func()
print 'Value of x is', x
????????code/func_global.py??
$ python func_global.py
x is 50
Changed global x to 2
Value of x is 2
global???????????x????????????????????????????????x?????????�£?????????????????????x????????
????????????global?????????????????????global x, y, z??
| ???? | ????? | ???? |
|---|---|---|
| ?????¦Â? | ??? | ??????? |