函数的返回值与作用域

# @Time     :2019/6/6 21:57
#-*- encoding:utf-8 -*-
# ##############################函数返回值与作用域
# 函数外部的代码要想获取函数的执行结果,就可以在函数里用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语句,就会停止执行并返回结果,那么也可以理解为 return 语句代表着函数的结束

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

猜你喜欢

转载自www.cnblogs.com/Demo-simple/p/11139771.html