Which of the following lines correctly invoke the function defined below:

Which of the following lines correctly invoke the function defined below:

def fun(a, b, c=0):

# Body of the function.

(Select two answers)
A . fun(0, 1, 2)
B. fun(b=0, a=0)
C. fun(b=1)
D. fun()

Answer: A,B

Explanation:

Topics: functions positional parameters keyword parameters

Try it yourself:

def fun(a, b, c=0):

# Body of the function.

pass

fun(b=0, a=0)

fun(0, 1, 2)

# fun() # TypeError: fun() missing 2 required

# positional arguments: ‘a’ and ‘b’

# fun(b=1) # TypeError: fun() missing 1 required

# positional argument: ‘a’

Only the parameter c has a default value.

Therefore you need at least two arguments.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments