Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question 9 what is the difference between *args and **kwargs in a funct…

Question

question 9
what is the difference between args and *kwargs in a function?
args is used for positional arguments, *kwargs is used for keyword arguments
args is used for keyword arguments, *kwargs is used for positional arguments
args is used for strings, *kwargs is used for numbers
there is no difference
question 10
what is the purpose of a try - except block in python?
to define a function
to handle potential errors in code
to create a loop
to print a value to the console

Explanation:

Brief Explanations

In Python, args is used to pass a non - keyworded variable - length argument list (positional arguments). It allows a function to accept an arbitrary number of positional arguments. For example, def my_func(args): can be called as my_func(1, 2, 3).

kwargs is used to pass keyworded variable - length of arguments. It allows a function to accept an arbitrary number of keyword arguments. For example, def my_func(kwargs): can be called as my_func(a = 1, b = 2).

Answer:

args is used for positional arguments, *kwargs is used for keyword arguments