How to create a function with arbitrary number of keyword parameters in Python

3 Answers

0 votes
def function(**keywords_args):
    print(keywords_args)


function(p="python", j="java", c="c#")


'''
run:

{'c': 'c#', 'p': 'python', 'j': 'java'}

'''

 



answered Dec 16, 2017 by avibootz
0 votes
def function(**keywords_args):
    for k in keywords_args:
        print(k)


function(pp="python", jj="java", cc="c#")


'''
run:

cc
pp
jj

'''

 



answered Dec 16, 2017 by avibootz
0 votes
def function(**keywords_args):
    for k in keywords_args:
        print(keywords_args[k])


function(pp="python", jj="java", cc="c#", dd="php")


'''
run:

java
c#
python
php

'''

 



answered Dec 16, 2017 by avibootz
edited Dec 17, 2017 by avibootz
...