zoukankan      html  css  js  c++  java
  • python_30期【函数里面不定长参数/动态参数 *arges**关键字参数**kwargs】

    #不定长参数/动态参数 *arges argument---arges 按这个规范
    #把这个数据 转成元组形成
    # def add(*args):
    #     print(args)
    #     print("arges的类型:",type(args))
    #     count=0
    #     for item in args:
    #         count+=item
    #     return count
    #
    #
    #
    # result=add(1,2,3,4,5,6,7,10,50,90,400)
    # print("动态参数的求和:",result)
    #1.什么时候用动态参数-->当你不确定这个参数的时候 就可以用动态参数
    
    
    #2.位置参数和动态参数的结合使用 位置参数放在动态参数前
    # def gree(cotent,*args):
    #     name=''
    #     for item in args:
    #         name+=item
    #         name+=','
    #     print(name,cotent)
    # gree("早上好","我是XX","在干什么呀!")
    #3.默认参数和动态参数的结合使用 默认参数不起作用了, 如果要默认参数需要放在动态参数后面
    def gree(*args,cotent='中午好'):
        name=''
        for item in args:
            name+=item
            name+=','
        print(name,cotent)
    gree("早上好","我是XX","在干什么呀!")
    #关键字参数 ** kearges key word arguments
    #参数类型:key value
    #结合默认值 默认值也必须放在关键参数前
    def vivo_info(age=18,**kwargs):
        print("age:",age)
        print("kwargs:",kwargs)
        for item in kwargs.values():
            print(item)
    
    vivo_info(t_name="xixi",class_01="测试",version="防沉迷")
  • 相关阅读:
    好多天没写了,郁闷
    昨天很受教育
    恼火的服务器
    欢迎访问我的博客网站
    体育产品论坛
    参考书目
    web2.0与数字标准
    用户产生内容与网站做内容
    Using x++ code reading data from csv file format
    Find out specified the folder for all the files
  • 原文地址:https://www.cnblogs.com/zhang-ping1205/p/12943866.html
Copyright © 2011-2022 走看看