Mar-29-2020, 12:11 PM
(Mar-29-2020, 08:02 AM)buran Wrote: def some_func(*args, **kwargs):I liked the example, it was very clear. But as DPaul said, why those asterisks? It doesn't make very clear what is going on. I think he would like to see something like:
def some_func(args=tuple(), kwargs=dict()):This makes clear what the arguments should be. And we prefer clear programs, don't we?
But then I tried to make it work. It appeared the calls to the function had to be altered:
some_func(('foo',), {'spam':1}) #was: some_func('foo', spam=1) some_func(('foo', 'bar'), #was: some_func('foo', 'bar', spam=1, eggs=2) {'spam':1, 'eggs':2}) some_func(pos) #was: some_func(*pos) some_func((), keyw) #was: some_func(**keyw) some_func(('foo',), keyw) #was: some_func('foo', **keyw) some_func(pos, keyw) #was: some_func(*pos, **keyw)Then I saw it didn't get much clearer after all. So the asterisks serve a purpose.