zoukankan      html  css  js  c++  java
  • Python学习之路:函数参数及调用

    return:结束函数并返回值

    没有return时:返回None

    返回值数=1时:返回具体值

    返回值是数字+字符串+列表等:返回一个元组

    需要return是需要函数完整调用

    def test1():
        print('in the test1')
    
    def test2():
        print('in the test2')
        return 0 #结束函数并返回0
    
    def test3():
        print('in the test3')
        return 1,'hello',['alex','wupeiqi'], {'name','alex'}#结束函数并返回0
    
    x=test1() #return返回值可以赋值给变量
    y=test2()
    z=test3()
    print(x)
    print(y)
    print(z)
    

     函数参数:

    def test(x,y):
        print(x)
        print(y)
    
    test(1,2) #1传给x,2传给y;x,y叫形参(位置参数);1,2叫实参;形参和实参的位置一一对应;
    test(y=1,x=2)#关键字调用:与形参顺序无关
    test(1,2)#位置参数调用:与形参一一对应
    test(3,y=2)#既有位置参数调用又有关键字参数调用,按位置参数调用执行
    
    
    def test(x,y,z):
        print(x)
        print(y)
        print(z)
    test(3,z=2,y=6)
    test(3,y=2,6)#关键字参数不能在位置参数前面
    
  • 相关阅读:
    delphi多线程加锁
    delphi中pchar、char、string的定义与区别
    delphi指针
    关于delphi函数的调用顺序问题
    easyexcel
    # springcloud-eureka-feign-mybatis-seata ### 整合步奏
    zuul网关
    ## feign远程调用开启熔断
    eureka2
    Eureka
  • 原文地址:https://www.cnblogs.com/xiaobai005/p/7834730.html
Copyright © 2011-2022 走看看