用Python代码实现 for遍历字典关键字,输出关键字为su的值
时间: 2023-06-05 20:04:27 浏览: 123
python工具,遍历Python关键字
当然,让我来回答您的问题。以下是Python代码实现for遍历字典关键字,输出关键字为"su"的值:
```python
my_dict = {"name": "Mary", "age": 25, "subject": "Maths", "surname": "Sue"}
for key, value in my_dict.items():
if key == "surname":
print(value)
```
这段代码会输出字典中关键字为"su"的值"Sue"。
阅读全文