2005年08月08日 星期一 20:21
>>> [] is None False >>> [] == None False >>> def foo(par=[]): if par is None: par = [] par.append(0) print par >>> foo() [] 上面是我的测试结果,没有问题,if后面的语句不会被执行,还有参数最好不要用[],请看:http://www.ferg.org/projects/python_gotchas.html#contents_item_6 ----- Original Message ----- From: 小楼听雨 To: python-chinese at lists.python.cn Sent: Tuesday, August 09, 2005 7:54 PM Subject: Re: Re: [python-chinese] two questions def foo(par=[]): if par is None: par = [] par.append(0) print par foo() print foo.func_defaults foo() print foo.func_defaults foo([9]) print foo.func_defaults foo() print foo.func_defaults 结果是: [] ([],) #为什么不是([0],) [] ([],) [9] ([],) [] ([],) 难道是par.append(0)的问题? ------------------------------------------------------------------------------ _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050808/81c7e5b6/attachment.html
Zeuux © 2025
京ICP备05028076号