zoukankan      html  css  js  c++  java
  • 函数补充

    注释(一定要写)

    1.要写当前函数具体的功能

    2.解释当前函数参数作用

    3.解释当前函数返回值的特点

    def index(x, y, z):
        return x,y,z
    
    
    a,*_ = index(1, 2, 3)
    print(a, _)
    print(a, *_)


    结果:

    1 [2, 3]
    1 2 3

    *  在函数定义中  接收所有溢出的位置参数,将接收的值以元组的形式传入*后面的变量中

       在调用函数中  将课迭代对象类型打散成位置参数

    **  在函数定义中  接收所有的关键字参数,以字典的形式传入**后面的变量中

       在调用函数中  将字典打散成关键字参数传入形参中

    命名关键字参数:

    https://www.cnblogs.com/shiliye/p/10906147.html

    定义在*和**之间

    在给命名关键字传值的时候一定要以关键字形式传递

    def index(x, y, z, a=1,*args,  b, **kwargs):
        print(x, y, z)
        print(args)
        print(a, b)
        print(kwargs)
    
    
    index(1, 2, 3, 354353, 4342, 3213123, 111, b=222, c=333, d=444)
    
    
    
    1 2 3
    (4342, 3213123, 111)
    354353 222
    {'c': 333, 'd': 444}
    def index(x, y, z, *args, a=1, b, **kwargs):
        print(x, y, z)
        print(args)
        print(a, b)
        print(kwargs)
    
    
    index(1, 2, 3, 354353, 4342, 3213123, 111, b=222, c=333, d=444)
    
    
    
    
    1 2 3
    (354353, 4342, 3213123, 111)
    1 222
    {'c': 333, 'd': 444}
  • 相关阅读:
    子查询
    关联,分组练习
    共享锁(S锁)和排它锁(X锁)
    mac 搭建Vue开发环境
    移动端web开发
    负margin
    关于前端的margin
    清除的通用样式 css
    css布局
    <div class="clear"></div>
  • 原文地址:https://www.cnblogs.com/godlover/p/11834689.html
Copyright © 2011-2022 走看看