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

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type