跳至内容
Python 俱乐部
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
functions:list-parameter
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Python函数参数为列表(list)且默认值为空列表 ====== python 函数参数默认值为列表时注意事项。 当python是一个函数中一参数默认值为一个列表时, 不像其它程序一样,每次调用函数中参数都为新的(初始化),而是只初始化一次。 ===== Python函数默认参数为空列表 ===== <code python> def PrintList(L=[]): L.append("hello") print L PrintList() PrintList() PrintList() </code> ===== 测试结果 ===== <code> >>> python test.py ['hello'] ['hello', 'hello'] ['hello', 'hello', 'hello'] </code> ===== 参考 ===== * http://www.scriptlearn.com/archives/604
functions/list-parameter.txt
· 最后更改: 2010/12/21 05:09 (外部编辑)
页面工具
显示页面
修订记录
反向链接
回到顶部