函数-返回值

函数外部的代码想要获取函数的执行结果,就可以在函数里用return语句把结果返回。

def stu_register(name,age,course='py',country='cn')

  print(-----注册学生信息-----)

  print(‘姓名’,name)

  print(‘age’,age)

  print(‘国籍’,country)

  print(‘课程’,course)

  if age>22:

    return False

  else:

    return True

#调用函数列子:

registriation_status = stu_register('王山炮',22,course=‘py全栈开发’,country='jp')

if registriation_status:

  print('注册成功')

else:

  print('too old to be a student.')

注意:

函数在执行过程中只要遇到return语句,就会停止执行并返回结果,so也可以理解为return语句代表着函数的结束

如果未在函数中指定return,那这个函数的返回值为None

猜你喜欢

转载自www.cnblogs.com/kingforn/p/10890766.html