📜  使用 None 将空参数作为 python 函数中的参数 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:20.540000             🧑  作者: Mango

代码示例1
def createStudent(name, age, grades=None):
  if grades is None:
    grades = []
  return {
    'name': name,
    'age': age,
    'grades': grades
  }
 
def addGrade(student, grade):
    student['grades'].append(grade)
    # To help visualize the grades we have added a print statement
    print(student['grades'])