1.

What is the usage of *args and **kwargs?

Answer»

In Python, we can pass a variable number of arguments to a function when we are unsure about how may arguments NEED to be passed to a function. These arguments can be passed using a special TYPE of symbols as depicted below.

  • *ARGS (Non-Keyword Arguments): This symbol is used in a function to pass a variable number of non-keyword arguments on which tuple operation can be performed. We use asterisk (*) symbol before the name of the parameter in ORDER to pass arguments of variable length.
  • **kwargs (Keyword Arguments): This symbol is used in a function to pass a variable number of keyword arguments dictionary on which dictionary operations can be performed We use double-asterisk (*) symbol before the name of the parameter in order to denote the argument type.

Function flexibility can be achieved by PASSING these two types of special symbols.



Discussion

No Comment Found