我是Python的新手,我正在尝试创建一个哈希表,检查键是否指向表中的值,如果不是,则将其初始化为空数组。我的代码中最让人反感的部分是:
converted_comments[submission.id] = converted_comments.get(submission.id, default=0)
我知道错误:
TypeError: get() takes no keyword arguments
但是在文档(以及各种示例代码)中,我可以看到它确实采用了一个默认参数:
https://docs.python.org/2/library/stdtypes.html#dict.gethttp://www.tutorialspoint.com/python/dictionary_get.htm
Following is the syntax for get() method:
dict.get(key, default=None)
这一点都没有,所以我认为这是初学者的错误?
错误消息说
get
不接受关键字参数,但您提供的是default=0
由于Python C级api的开发方式,许多内置函数和方法的参数实际上没有名称。即使文档调用参数
default
,函数也不会将名称default
识别为引用可选的第二个参数。必须按位置提供参数:相关问题 更多 >
编程相关推荐