def calc(*args, **kwargs): print('args ',args) print('kwargs' ,kwargs) calc(1,2,3,4) calc((1,2,3),(4,5)) calc(1,2,3,(4,5),a=1,b=2)
# args (1, 2, 3, 4)
# kwargs {}
# args ((1, 2, 3), (4, 5))
# kwargs {}
# args (1, 2, 3, (4, 5))
# kwargs {'a': 1, 'b': 2}spa
*args,**kwargscode
都是可變長參數;blog
*args:表示任意多個無名參數,返回一個tupleio
**kwargs:表示關鍵字參數,返回一個字典class