WILL UPVOTE!! Question 31 2.5 pts Which of the following is true? When defining
ID: 3915356 • Letter: W
Question
WILL UPVOTE!!
Question 31 2.5 pts Which of the following is true? When defining a function, non-default arguments can appear after default arguments in the function's header When defining a function, it is illegal to provide default values for all arguments in the function's header When calling a function, we can combine positional and keyword arguments in any order When calling a function, positional arguments cannot appear after keyword arguments Question 32 2.5 pts What is the output of the following program? def f2(x, y): return x+ y a f2(2, 4) at 1 def f1 (x-a): print(x) f10Explanation / Answer
Question 31:-
1. when defining a function, non default arguments can appear after default arguments in functions header - False
If, non default arguments can appear after default arguments , we get compilation error stating :-"non default arguments follows default argument"
example:- def greet(name="Kate", msg ):
print("Hello",name + ', ' + msg)
greet( "Good morning!")
output:-non default arguments follows default argument
2. when defining a function, it is illegal to provide default values for all arguments in the function header - False
All the values provided in a function be default
Example:- def greet(name="Kate", msg = "Good morning!" ):
print("Hello",name + ', ' + msg)
greet()
Output:- Hello Kate, Good morning!
3. when calling a function, we can combine positional and keyword arguments in any order - True
Example:- def greet(name, msg ):
print("Hello",name + ', ' + msg)
# 1 positional, 1 keyword argument
greet("Bruce",msg = "How do you do?")
Output:-Hello Bruce, How do you do?
4. when calling a function, positional arguments cannot appear after keyword arguments - False
keyword arguments must follow positional arguments.
Example:- def greet(name, msg ):
print("Hello",name + ', ' + msg)
greet(name="Bruce","How do you do?")
Output :-positional argument follows keyword argument
Question 32:-
def f2(x,y):
return x+y
a=f2(2,4) //a=6
a+=1 //a=7
def f1(x=a): //here x will be equal to 7 since while defining the function it refers to a which is already defined which have value 7
print(x)
a=5 //here value of a will change to 5 but x will still hold 7
f1() //call the function
output :-7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.