• 3 返回值


    返回值
    函数外部的代码要想获取函数的执行结果,就可以在函数里用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

  • 相关阅读:
    requirejs 第一个实例
    ionic + cordova 环境搭建
    免安装mysql配置
    ConcurrentHashMap
    volatile和synchronized
    zookeeper集群安装
    题目
    Nginx
    CountDownLatch
    自己总结
  • 原文地址:https://www.cnblogs.com/shibojie/p/11658256.html
Copyright © 2020-2023  润新知