You can pass your parameters as keyword arguments : -
def __init__(self, **kwargs): self.args = kwargs
Then you will create an instance of your class as follows: -
myClassObj = MyClass(a=12, b="abc")
Then your args dict will contain these arguments as a key-value pair: -
{'a':12, 'b':'abc'}
to access attributes: -
myClassObj.args['a'] myClassObj.args['b']
You can also pass a combination of different arguments. There are four types of arguments that you can have in any function: -
- Positional argument
- Default argument
- Keyless argument.
- Keyword Argument.
Only in that order. Thus, the typical syntax for declaring a function is: -
def func(positional_arg, default_arg, *nkwargs, **kwargs)
For more information on defining functions, see.
source share