for stu_dict in student:
print(stu_dict)
if stu_dict['name']==find_name:
print('找到了%s'%find_name)
break
else:
print('抱歉,没有找到%s'%find_name)
print('over')
结果是:
{'name': 'xiao'}
抱歉,没有找到heiq
{'name': 'hei'}
抱歉,没有找到heiq
over
```python
student =[{'name':'xiao'},
{'name':'hei'}]
find_name ="heiq"
for stu_dict in student:
print(stu_dict)
if stu_dict['name']==find_name:
print('找到了%s'%find_name)
break
else:
print('抱歉,没有找到%s'%find_name)
print('over')
结果是:
{'name': 'xiao'}
{'name': 'hei'}
抱歉,没有找到heiq
over