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)
8
6
64
2
Answer: Option
Explanation:
The function power raises 2 to the power of 3, resulting in 8.

32.
What does the term "function overloading" mean?
Defining multiple functions with the same name but different parameters
A function calling itself
The process of reducing the size of a function
Using multiple functions to overload the program
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)
10
1234
[1, 2, 3, 4]
Error
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?
Using the global keyword
Using the local keyword
Using the global_scope() function
Using the global_variable parameter
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?
Checks if a variable is of a certain type
Determines if an object is callable as a function
Converts a string to uppercase
Creates a new list with specified values
Answer: Option
Explanation:
The callable() function checks if an object can be called as a function.