Re: help, thanks very much.
ww <[email protected]> Tue, 22 Jan 2008 13:22:53 +0800
| Newsgroups | gmane.comp.python.chinese |
|---|---|
| Message-ID | <[email protected]> |
func(x)的x是参数,是调用函数是传给它的,不带x的函数,如果直接在函数内部 使用x,是局部变量,所以要用global特地说明一下,是引用函数外面定义的变量 ,这两个函数的结果是一样的。 On Wed, 16 Jan 2008 09:54:42 +0800 "bill.wu" <[email protected]> wrote: > 我想问一下,这两个函数的的 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 -- ww <[email protected]> _______________________________________________ python-chinese Post: send [email protected] Subscribe: send subscribe to [email protected] Unsubscribe: send unsubscribe to [email protected] Detail Info: http://python.cn/mailman/listinfo/python-chinese