Python:字典中的AttributeError

2024-04-20 03:16:23 发布

您现在位置:Python中文网/ 问答频道 /正文

在执行代码之后,我得到了AttributeError

AttributeError: 'dict' object has no attribute 'coeffs' 

这是什么意思?我该怎么解决这个问题?你知道吗

我是被自动分级机弄错的。 谢谢你的帮助!:)


Tags: no代码objectattributedict分级机attributeerrorhas
2条回答

如果您有一个键为coeffs的dictionary对象,那么您可以尝试使用

your_dict.coeffs

这不是在Python中访问dict中的键的方式,您可以这样做your_dict['coeffs']

你也可以用 your_dict.get('coeffs')

它允许您指定“默认”值:

your_dict.get('coeffs', default_value)

如果密钥不存在。你知道吗

当你不确定钥匙是否已经存在于字典中时非常有用

相关问题 更多 >