python - Positional and optional parameters in functions -


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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -