Question 1
What is a function in Python?
A keyword
A type of variable
An imported library
A block of code that performs a specific task.
Question 2
Which of the following keyword is used to define a function in Python?
func
def
class
void
Question 3
What happens when a variable is defined inside a function and you attempt to access it from outside that function's body?
The variable is accessed normally.
The variable is stored in the global namespace.
The value returns as 'None'.
Python raises a NameError because the variable exists only in the local scope.
Question 4
Which specific keyword is required to modify a variable in the outer (enclosing) function from within an inner function?
self
global
nonlocal
static
Question 5
If a function is defined to return a value but does not include a return statement, what will be the result?
The function will return a default value of 0
The function will return an error
The function will return None
The function will return the last executed statement
Question 6
Which of the following statements about functions returning other functions is true?
A function cannot return another function in Python
The returned function can access variables from the outer function
The returned function must be called immediately
The outer function's execution must be completed before returning
Question 7
Which keyword is used in Python to create an anonymous function that can be defined in a single line without a name?
anonymous
inline
lambda
def
Question 8
What is the output of the following program :
y = 8
z = lambda x : x * y
print(z(6))
48
14
64
None of the above
Question 9
What is the primary difference between *args and **kwargs?
*args handles keyword arguments, while **kwargs handles positional arguments.
*args is used for recursion, while **kwargs is used for iteration.
*args collects arguments into a list, while **kwargs collects them into a tuple.
*args collects positional arguments into a tuple, while **kwargs collects keyword arguments into a dictionary.
Question 10
What is the output of the following program?
def update_val(x):
x = x + 10
num = 5
update_val(num)
print(num)
15
None
5
Error: local variable referenced before assignment
There are 13 questions to complete.