gpt4 book ai didi

python - Python 中的可变默认方法参数

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:06 26 4
gpt4 key购买 nike

<分区>

我正在使用 Python IDE PyCharm,默认情况下它会在我将 mutbale 类型作为默认值时显示警告。例如,当我有这个时:

def status(self, options=[]):

PyCharm 希望它看起来像:

def status(self, options=None):
if not options: options = []

我的问题是,这是否是 Python 社区中的标准做事方式,或者这只是 PyCharm 认为应该做的方式吗?将可变数据类型作为默认方法参数有什么缺点吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com