学生管理系统python函数
时间: 2023-08-23 21:08:09 浏览: 100
python学生管理系统
以下是一个基本的学生管理系统的 Python 函数示例:
```python
def add_student(name, age, grade):
"""添加学生信息"""
student = {"name": name, "age": age, "grade": grade}
students.append(student)
def remove_student(name):
"""删除学生信息"""
for student in students:
if student["name"] == name:
students.remove(student)
def update_student(name, new_age=None, new_grade=None):
"""更新学生信息"""
for student in students:
if student["name"] == name:
if new_age:
student["age"] = new_age
if new_grade:
student["grade"] = new_grade
def search_student(name):
"""查询学生信息"""
for student in students:
if student["name"] == name:
return student
return None
def display_all_students():
"""显示所有学生信息"""
for student in students:
print(student)
students = []
add_student("张三", 18, "大一")
add_student("李四", 19, "大二")
display_all_students()
remove_student("张三")
display_all_students()
update_student("李四", new_age=20, new_grade="大三")
display_all_students()
student = search_student("李四")
print(student)
```
这个示例中包含了添加、删除、更新、查询和显示所有学生信息这些基本操作。当然,这只是一个简单的示例,你可以根据自己的需要对这些函数进行修改和扩展。
阅读全文