不定参数

#!/usr/bin/env python
# -*- coding:utf-8 -*-


def fun1( *args, **kwargs ):
    print( args, type(args) )
    print( kwargs, type(args) )

fun1(12, 'aa', 234, kk=1, nn=4)
aa=[1, 2, 3, 4]
b = {'a': 1, 'b': 2, 'c': 3}
fun1(*aa, **b)

C:UsersDELLAppDataLocalProgramsPythonPython35python.exe I:/untitled1/b.py
(12, 'aa', 234) <class 'tuple'>
{'nn': 4, 'kk': 1} <class 'tuple'>
(1, 2, 3, 4) <class 'tuple'>
{'b': 2, 'c': 3, 'a': 1} <class 'tuple'>

原文地址:https://www.cnblogs.com/y990441/p/6257688.html