• 函数和过程


    过程定义:过程就是简单特殊没有返回值的函数

    这么看来我们在讨论为何使用函数的的时候引入的函数,都没有返回值,没有返回值就是过程,没错,但是在python中有比较神奇的事情

    def test01():
        msg='hello The little green frog'
        print msg
     
    def test02():
        msg='hello WuDaLang'
        print msg
        return msg
     
     
    t1=test01()
     
    t2=test02()
     
     
    print 'from test01 return is [%s]' %t1
    print 'from test02 return is [%s]' %t2

    总结:当一个函数/过程没有使用return显示的定义返回值时,python解释器会隐式的返回None,

    所以在python中即便是过程也可以算作函数。

    def test01():
        pass
     
    def test02():
        return 0
     
    def test03():
        return 0,10,'hello',['alex','lb'],{'WuDaLang':'lb'}
     
    t1=test01()
    t2=test02()
    t3=test03()
     
     
    print 'from test01 return is [%s]: ' %type(t1),t1
    print 'from test02 return is [%s]: ' %type(t2),t2
    print 'from test03 return is [%s]: ' %type(t3),t3

    总结:

       返回值数=0:返回None

       返回值数=1:返回object

       返回值数>1:返回tuple

  • 相关阅读:
    python内置函数枚举 enumerate()
    python内置函数map的介绍
    什么是lambda函数
    python urllib库 加密及解析url中中文汉字
    python解决高并发思路
    后端文件保存的两种方式
    matplotlib基本用法
    自编码器
    数据增强
    卷积神经网络
  • 原文地址:https://www.cnblogs.com/hui147258/p/10855599.html
Copyright © 2020-2023  润新知