#1
Which of the following is true about function invocation in Python?
Functions cannot be called in Python
Functions are invoked using the 'call' keyword
Functions are invoked using their name followed by parentheses
Functions can only be invoked within classes
#2
What happens if a function in Python is called with too many arguments?
An error is raised
Extra arguments are ignored
The function automatically adjusts to accommodate all arguments
The function replaces existing arguments with new ones
#3
What is the purpose of the return statement in Python functions?
To terminate the function immediately
To return a value from the function
To print output to the console
To define default values for parameters
#4
In Python, how are named parameters specified in a function call?
By enclosing them in parentheses
By using the 'named' keyword
By specifying their names followed by an equal sign and the value
Named parameters are not allowed in Python function calls
#5
What is the purpose of the * operator in Python function calls?
To multiply the arguments passed to the function
To unpack a tuple or list into separate arguments
To concatenate strings
To divide the arguments passed to the function
#6
Which of the following is true about default parameter values in Python functions?
Default parameter values must always be of the same type
Default parameter values can only be specified for the last parameter
Default parameter values are evaluated at the time of function definition
Default parameter values can only be specified for integer parameters
#7
What is the purpose of the *args and **kwargs parameters in Python function definitions?
To specify mandatory arguments
To accept a variable number of positional and keyword arguments, respectively
To define default arguments
To specify variable-length arguments
#8
Which of the following is true about function documentation strings (docstrings) in Python?
Docstrings are optional
Docstrings are enclosed within triple double quotes
Docstrings are used to specify default parameter values
Docstrings are used to execute additional code when the function is called
#9
What does the term 'scope' refer to in Python?
The visibility of variables within a program
The size of the codebase
The speed of execution of a program
The memory allocated to a program
#10
How are variable scopes determined in Python?
By their position within the source code
By their data type
By their length
By the 'global' and 'local' keywords
#11
In Python, how are default parameter values specified in a function definition?
Using curly braces
Using the 'default' keyword
By assigning values directly in the parameter list
Default values are not allowed in Python functions
#12
What is the purpose of the *args parameter in Python function definitions?
To specify default arguments
To accept a variable number of positional arguments
To accept keyword arguments
To specify mandatory arguments
#13
What is the purpose of the global keyword in Python?
To define a global variable within a function
To declare a variable outside a function
To access a global variable inside a function
To indicate that a function can be accessed globally
#14
What does the locals() function return in Python?
All global variables
All local variables
A dictionary containing all local variables
A dictionary containing all global variables
#15
What is the purpose of the nonlocal keyword in Python?
To define a variable as local to a specific function
To declare a variable outside all functions
To access a variable in the global scope from within a nested function
To indicate that a variable is not local to any function
#16
In Python, what is the purpose of the ** operator when used in a function call?
To exponentiate the arguments passed to the function
To unpack a dictionary into keyword arguments
To perform bitwise AND operation on the arguments
To calculate the square root of the arguments passed to the function
#17
What is the purpose of the __init__() method in Python classes?
To initialize class attributes
To define a new instance method
To terminate the execution of a class
To specify default parameter values for class methods
#18
What is the difference between a function and a method in Python?
Functions are defined within classes, while methods are defined outside classes
Functions can only accept positional arguments, while methods can accept both positional and keyword arguments
Functions are called using the 'call' keyword, while methods are invoked using their name followed by parentheses
Functions are independent entities, while methods are associated with objects or classes
#19
What is the purpose of a closure in Python?
To define a function inside another function
To return a function from another function
To create a variable within a function
To call a function with specific arguments
#20
What is the difference between the 'return' and 'yield' statements in Python?
There is no difference; they serve the same purpose
The 'return' statement is used in generator functions, while 'yield' is used in regular functions
The 'return' statement terminates the function and returns a value, while 'yield' suspends the function's execution and yields a value
The 'return' statement yields a value, while 'yield' returns a value
#21
What does the **kwargs parameter allow you to do in Python function definitions?
Define default keyword arguments
Accept a variable number of keyword arguments
Specify required keyword arguments
Define variable-length arguments
#22
What is a lambda function in Python?
A function defined using the 'lambda' keyword
A function that accepts a variable number of arguments
A function with no return statement
A function that cannot be passed as an argument
#23
What is the purpose of the yield keyword in Python?
To return a value from a generator function
To define a function as a generator
To create an infinite loop
To terminate the execution of a function
#24
What is a decorator in Python?
A function that modifies the behavior of another function
A method used to remove elements from a list
A special type of variable used in object-oriented programming
A keyword used to define private methods in a class
#25
What is a generator in Python?
A built-in function used to generate random numbers
A function that generates a sequence of values lazily
A function that generates a fixed-size collection of values
A function that returns a single value