2006年06月20日 星期二 23:21
什么是mutable,immutable类型,如果immutable的类型,怎样绕道而行? xxmplus 写道: > 那要看a的类型,如果是mutable的类型就可以那么做,如果immutable的类型就 > 不行,要绕道而行 > > http://www.poromenos.org/tutorials/python > > On 6/21/06, crocodile.liu <crocodile.liu at 163.com> wrote: >> >> 我想在运行fun2后修改a的值 >> >> crocodile.liu 写道: >> > xxmplus 写道: >> > >> >> a的确是fun1的局部变量,所以和fun2没关系,你要把它传给fun2才行 >> >> >> >> On 6/21/06, crocodile.liu <crocodile.liu at 163.com> wrote: >> >> >> >>> def fun2(): >> >>> a+=1 >> >>> print a >> >>> def fun1(): >> >>> a=1 >> >>> fun2() >> >>> fun1() >> >>> 我想让a作为fun1的局部变量,但实际运行起来确不行? >> >>> >> >>> _______________________________________________ >> >>> python-chinese >> >>> Post: send python-chinese at lists.python.cn >> >>> Subscribe: send subscribe to python-chinese-request at lists.python.cn >> >>> Unsubscribe: send unsubscribe to >> python-chinese-request at lists.python.cn >> >>> Detail Info: http://python.cn/mailman/listinfo/python-chinese >> >>> >> >>> >> >> >> ------------------------------------------------------------------------ >> >> >> >> _______________________________________________ >> >> python-chinese >> >> Post: send python-chinese at lists.python.cn >> >> Subscribe: send subscribe to python-chinese-request at lists.python.cn >> >> Unsubscribe: send unsubscribe to >> python-chinese-request at lists.python.cn >> >> Detail Info: http://python.cn/mailman/listinfo/python-chinese >> >> >> > >> > >> > _______________________________________________ >> > python-chinese >> > Post: send python-chinese at lists.python.cn >> > Subscribe: send subscribe to python-chinese-request at lists.python.cn >> > Unsubscribe: send unsubscribe to >> python-chinese-request at lists.python.cn >> > Detail Info: http://python.cn/mailman/listinfo/python-chinese >> > >> > >> > >> >> >>
2006年06月20日 星期二 23:41
看不明白什么意思 On 6/20/06, crocodile.liu <crocodile.liu at 163.com> wrote: > > > 什么是mutable,immutable类型,如果immutable的类型,怎样绕道而行? > > xxmplus 写道: > > 那要看a的类型,如果是mutable的类型就可以那么做,如果immutable的类型就 > > 不行,要绕道而行 > > > > http://www.poromenos.org/tutorials/python > > > > On 6/21/06, crocodile.liu <crocodile.liu at 163.com> wrote: > >> > >> 我想在运行fun2后修改a的值 > >> > >> crocodile.liu 写道: > >> > xxmplus 写道: > >> > > >> >> a的确是fun1的局部变量,所以和fun2没关系,你要把它传给fun2才行 > >> >> > >> >> On 6/21/06, crocodile.liu <crocodile.liu at 163.com> wrote: > >> >> > >> >>> def fun2(): > >> >>> a+=1 > >> >>> print a > >> >>> def fun1(): > >> >>> a=1 > >> >>> fun2() > >> >>> fun1() > >> >>> 我想让a作为fun1的局部变量,但实际运行起来确不行? > >> >>> > >> >>> _______________________________________________ > >> >>> python-chinese > >> >>> Post: send python-chinese at lists.python.cn > >> >>> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >> >>> Unsubscribe: send unsubscribe to > >> python-chinese-request at lists.python.cn > >> >>> Detail Info: http://python.cn/mailman/listinfo/python-chinese > >> >>> > >> >>> > >> >> > >> > ------------------------------------------------------------------------ > >> >> > >> >> _______________________________________________ > >> >> python-chinese > >> >> Post: send python-chinese at lists.python.cn > >> >> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >> >> Unsubscribe: send unsubscribe to > >> python-chinese-request at lists.python.cn > >> >> Detail Info: http://python.cn/mailman/listinfo/python-chinese > >> >> > >> > > >> > > >> > _______________________________________________ > >> > python-chinese > >> > Post: send python-chinese at lists.python.cn > >> > Subscribe: send subscribe to python-chinese-request at lists.python.cn > >> > Unsubscribe: send unsubscribe to > >> python-chinese-request at lists.python.cn > >> > Detail Info: http://python.cn/mailman/listinfo/python-chinese > >> > > >> > > >> > > >> > >> > >> > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Robert Python源码剖析――http://blog.donews.com/lemur/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060620/a8f1ddb1/attachment.htm
2006年06月20日 星期二 23:44
我表达能力有这么糟糕么-__- On 6/21/06, Robert Chen <search.pythoner at gmail.com> wrote: > 看不明白什么意思 > >
2006年06月20日 星期二 23:47
你想在func2中修改func1中的局部变量? 狂晕!! -- http://codeplayer.blogbus.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060620/6548237b/attachment.html
2006年06月21日 星期三 08:55
On 6/20/06, crocodile.liu <crocodile.liu at 163.com> wrote: > > 什么是mutable,immutable类型,如果immutable的类型,怎样绕道而行? > > xxmplus 写道: > > 那要看a的类型,如果是mutable的类型就可以那么做,如果immutable的类型就 > > 不行,要绕道而行 > > 局部变量就是不希望让人去改变的,因此不要想着在一个函数中修改另一个函数的变量。如果想改,建议你使用全局变量。因为一个函数如果可以不通过传入参数或全局变量的方式去改变的化,这个函数的封装性就有问题,不容易维护了。所以这根本不是一个应该做的,也没有必要去想如何实现。 -- I like python! My Blog: http://www.donews.net/limodou My Django Site: http://www.djangocn.org NewEdit Maillist: http://groups.google.com/group/NewEdit
Zeuux © 2025
京ICP备05028076号