Rs: help, thanks very much.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Rs: help, thanks very much.

bill.wu
Mail
我想问一下,这两个函数的的 def func(x)和func() 一个带X一个不带X,请问是什么区别?为什么?
 
 
(1)
 
def func(x):
    print 'x is', x
    x = 2
    print 'Changed local x to', x

x = 50
func(x)
print 'x is still', x
(2)
 
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
____________________________________________________________________
____________________________________________
DreamMail - 电子邮件新体验 www.dreammail.org

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: Rs: help, thanks very much.

Lich_Ray
一个修改本地变量一个修改全局变量呗。

在08-1-16,bill.wu <[hidden email]> 写道:
我想问一下,这两个函数的的 def func(x)和func() 一个带X一个不带X,请问是什么区别?为什么?
 
 
(1)
 
def func(x):
    print 'x is', x
    x = 2
    print 'Changed local x to', x

x = 50
func(x)
print 'x is still', x
(2)
 
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
____________________________________________________________________
____________________________________________
DreamMail - 电子邮件新体验  <a href="http://www.dreammail.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">www.dreammail.org

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese



--
Ray Stinger, nickname Lich_Ray
God is in his heaven, all's right with the world.
-------------------------------------------------
let focus = 'computing' in where:
http://lichray.javaeye.com
let focus = 'computing' in here:
http://lichray.bokeland.com
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese