Python: 练习 不定长参数
a = 'aa' b = 'bb' tuple_ = (a, b) dict_ = {'c': 'cc', 'd': 'dd'} def test(*args, **kwargs): print(args) for item in args: print(item) print(kwargs) for key, value in kwargs.items(): print(key, value) if __name__ == '__main__': test('vv', 'ww', x='xx', y='yy', *tuple_, **dict_)
结果: ('vv', 'ww', 'aa', 'bb') vv ww aa bb {'x': 'xx', 'y': 'yy', 'c': 'cc', 'd': 'dd'} x xx y yy c cc d dd 进程已结束,退出代码0