python - Positional and optional parameters in functions -
this question has answer here:
i trying pass both positional , optional parameters function.
the below code works in python 3:
def something(*args, cookie=none): arg in args: print(arg) print('cookie ' + cookie) something('a', 'b', 'c', cookie='oreo')
but gives
syntaxerror: invalid syntax
when using python 2.
is possible in python 2?
if modify function slightly, can make work. looks python2 doesn't support exact syntax hoping for. syntax used works in python3 though.
def something(*args, **kwargs): arg in args: print(arg) print('cookie ' + kwargs['cookie'])
Comments
Post a Comment