kwargs与args的用法区别

kwargs就是当你传入key=value是存储的字典,args是元组

def foo(*args, **kwargs):
    print('args = ', args)
    print('kwargs = ', kwargs)
    print('---------------------------------------')

if __name__ == '__main__':
    foo(1, 2, 3, 4)
    foo(a=1, b=2, c=3)
    foo(1, 2, 3, 4, a=1, b=2, c=3)
    foo('a', 1, None, a=1, b='2', c=3)

 

posted on 2021-02-01 14:36  玩转机器学习  阅读(465)  评论(0编辑  收藏  举报