Python Programming - Functions
Exercise : Functions - General Questions
- Functions - General Questions
31.
What will be the output of the following code snippet?
def power(x, n=2):
return x ** n
result = power(2, 3)
print(result)
Answer: Option
Explanation:
The function
power
raises 2 to the power of 3, resulting in 8.
32.
What does the term "function overloading" mean?
Answer: Option
Explanation:
Function overloading in Python involves defining multiple functions with the same name but different parameters.
33.
What will be the output of the following code snippet?
def add(a, b):
return a + b
numbers = [1, 2, 3, 4]
result = add(*numbers)
print(result)
Answer: Option
Explanation:
The
*numbers
syntax unpacks the list, and the function add
adds all elements together.
34.
How do you define a variable with a global scope inside a function?
Answer: Option
Explanation:
The
global
keyword is used to declare a variable with a global scope inside a function.
35.
What is the purpose of the
callable()
function?
Answer: Option
Explanation:
The
callable()
function checks if an object can be called as a function.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers