*args和**kwargs

# -*- coding:utf-8
from functools import reduce

def test_args(f_arg,*args):
    print("f_arg is", f_arg)
    for arg in args:
        print ("another arg through *args",arg)


def test_kwargs(**kwargs):
    for key,value in kwargs.items():
        print ("key={0},value={1}".format(key,value))

if __name__ == "__main__":
    dic = {"name":"python","age":12}
    # test_kwargs(**dic)
    test_kwargs(name="python",age=12)

    args = (1,2,3,4) #元组和列表都行
    test_args("first",*args)
原文地址:https://www.cnblogs.com/python-kp/p/12581524.html