• 自定义函数基础-返回值,单值、多值


    • 有返回值(单值)

      def function(p1,p2)

        ...

        return

    # -*- coding: cp936 -*-
    def test_a():
        print '  Hello the bling'
        print '  www.bling.com'
    def test_b(p1,p2):#函数定义,形参
        print p1,
        print p2
    def test_c(p1,p2):#函数定义,形参,有返回值
        print p1,
        print p2
        p = p1+p2
        return p
    print 'Entry programme'
    test_a()
    test_b('yml',',jun')#函数调用,实参
    test_b(11,13)
    sum = test_c(20,21)
    print 'sum = ',sum
    print 'Leave programme'
    #输出
    Entry programme
      Hello the bling
      www.bling.com
    yml ,jun
    11 13
    20 21
    sum =  41
    Leave programme

    有多个值返回

      def function(p1,p2,...)

        s1,s2....

        return v1,v2,v3..

    # -*- coding: cp936 -*-
    def test_a():
        print '  Hello the bling'
        print '  www.bling.com'
    def test_b(p1,p2):#函数定义,形参
        print p1,
        print p2
    def test_c(p1,p2):#函数定义,形参,有返回值
        print p1,
        print p2
        p = p1+p2
        return p
    def test_d(p1,p2):#函数定义,形参,有返回值
        print p1,
        print p2
        n = p1+p2
        m = p1*p2
        e = p1**p2
        p = p1-p2
        return n,m,e,p
    print 'Entry programme'
    test_a()
    test_b('yml',',jun')#函数调用,实参
    test_b(11,13)
    sum = test_c(20,21)
    print 'sum = ',sum
    sum1,muti,pow,plus = test_d(2,10)
    print sum1,muti,pow,plus
    re = test_d(2,10)
    print re[0],re[1],re[2],re[3]
    print 'Leave programme'
    #输出
    Entry programme
      Hello the bling
      www.bling.com
    yml ,jun
    11 13
    20 21
    sum =  41
    2 10
    12 20 1024 -8
    2 10
    12 20 1024 -8
    Leave programme
  • 相关阅读:
    单例模式
    pandas to_html
    restful
    numpy版本查看以及升降
    视频下载
    转载:caffe中的Reshape层
    caffe编译报错解决
    python 版Faster Rcnn
    转载:动态规划以及路径记录
    TensorFlow设置GPU占用量
  • 原文地址:https://www.cnblogs.com/yangml/p/3859298.html
Copyright © 2020-2023  润新知