{'materialName': '金刚砂打磨头', 'materialModel': 'wurth', 'giveoutNum': '12', 'supplyName': 'liuke', 'edit': '删除'}python中怎样取出属性值
时间: 2024-03-16 12:38:34 浏览: 17
在Python中,可以使用点号(.)来访问对象的属性值。对于给定的字典对象,可以使用键来获取相应的属性值。以下是一个示例代码:
```python
data = {'materialName': '金刚砂打磨头', 'materialModel': 'wurth', 'giveoutNum': '12', 'supplyName': 'liuke', 'edit': '删除'}
# 使用点号访问属性值
material_name = data.materialName
material_model = data.materialModel
giveout_num = data.giveoutNum
supply_name = data.supplyName
edit = data.edit
# 使用键访问属性值
material_name = data['materialName']
material_model = data['materialModel']
giveout_num = data['giveoutNum']
supply_name = data['supplyName']
edit = data['edit']
```
请注意,如果属性不存在,将会引发`AttributeError`或`KeyError`异常。因此,在访问属性值之前,最好先检查属性是否存在。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)