The use of a single asterisk (*) before the parameter name (arg) indicates that it can accept a variable number of unnamed positional arguments. When the function is called, these arguments will be collected into a tuple named arg.
The **args parameter, with two asterisks (**), allows for a variable number of keyword arguments to be passed to the function. These arguments will be collected into a dictionary named args.
The code is correct. its important oto note that *followed by any name means a tuple of variable number of unnamed positional arguments, and **followed by any name means variable number of keyword arguments. this means code is correct. *args, **kwargs are just a convention.
B is not the Valid answer. But A is valid one. because *args or *arg in python hold possition argument as turple and not as list. So its false to say *args hold information as list.
A is correct.
B is wrong since *arg is a tuple, not a list
C is wrong since *arg is the placeholder for unnamed arguments
D is wrong since the parameter names can be changed
code:
def f1(*arg, **args):
print(arg, type(arg))
print(args, type(args))
f1(1, 2, 3, a=1, b=2, c=3)
output:
(1, 2, 3) <class 'tuple'>
{'a': 1, 'b': 2, 'c': 3} <class 'dict'>
What happens here is that **args is the same variable as *args. Therefore, the placeholder for positional arguments (unnamed arguments) is replaced by the named arguments. Correct answer is C
Wrong. C is incorrect.
They are two different variables, one is named "arg", the other "args".
*arg holds the unnamed arguments
**args hold the named arguments.
upvoted 1 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
cubesmi
Highly Voted 1 year, 7 months agoherrmann69
8 months agodeyoz
Most Recent 4 weeks, 1 day agoXRay70
1 month, 1 week ago2211094
4 months, 1 week ago2211094
4 months, 2 weeks agoDiscussoR
6 months, 2 weeks agoherrmann69
8 months agomademade
9 months agorafles
1 year, 7 months agoherrmann69
8 months ago