python function with variable keyword argument

In Python, we have function that accepts variable keyword argument.  This makes it easy to pass function without resorting to using too many parameters. The example below helps to provide one example, how to pass this in and get some understanding of how to work with these values.


# get key
def test(**kwargs):
  # unpacking
  a, b = kwargs
  print(a)
  print(b)
  print(kwargs)

# get values
def test(**kwargs):
  # unpacking
  a, b = kwargs.values()
  print(a)
  print(b)
  print(kwargs)

let a = {"test": "test1", "name":"test2"}
test(**a)

 



Comments

Popular posts from this blog

vllm : Failed to infer device type

android studio kotlin source is null error

gemini cli getting file not defined error