学生管理系统💓
def show_menu():
print("----------------------------")
print("|1.添加学生信息")
print("|2.查询学生信息")
print("|3.退出系统")
print("----------------------------")
def add_student(name,age,grade,student_id =None):
if student_id is None:
student_id = len(students) + 1001
student = {
"name":name,
"age":age,
"grade":grade,
"id":student_id
}
students.append(student)
print(f"成功添加学生:{name}(id:{student_id}")
show_menu()
choice = input("请输入您的选择:")
show_menu()
参数传递❣️
- 位置参数的传递 (函数调用时 实参 按照“位置”依次传递给 形参)
- 关键字参数的传递 (“形参=实参”,将 实参 按照对应的 “关键字” 传递给 形参)
- 默认参数的传递 (函数定义时可以指定形参的默认值,调用可以直接用默认值,也可以修改
注意:默认形参后面不能有非默认形参!!!!!)
- 参数的打包与解包(1.函数定义时无法确定接收多少个数据 2.函数调用时接收实参是元祖,使用"*"
3.函数调用时接收实参是字典,使用"**",接收值)
print("------参数传递------")
def get_max(a,b):
"""比较a和b的大小"""
if a>b:
print(a,"比较大")
else:
print(b,"比较大")
get_max(5,20)
print("------关键字参数的传递------")
def connect(ip,port):
"""连接设备"""
print(f"设备{ip}:{port}连接")
connect(ip="127.0.01", port=8080)
print("------默认参数的传递------")
def connect(ip,port=8080):
"""连接设备"""
print(f"设备{ip}:{port}连接")
connect(ip="127.0.02")
connect(ip="127.0.03",port=3306)
print(------参数的打包与解包------)
def test(*args):
print(args)
test("Python","a",23,56)
print("------解包------")
def test(a,b,c,d,e):
print(a,b,c,d,e)
nums = (12,22,33,44,55)
test(*nums)
nums = {"a":12,"b":22,"c":33,"d":44,"e":55}
test(**nums)