What does the return statement in a function do?
A. It specifies the value to be returned from the function
B. It ends the execution of the function
C. It prints the result on the screen
D. It defines the function's name
Select an option to see the answer and solution.
How can you make a parameter optional in a Python function?
A. By using the optional keyword
B. By providing a default value to the parameter
C. By making the parameter lowercase
D. By using a special keyword opt
Select an option to see the answer and solution.
Which of the following is NOT a valid function name in Python?
A. my_function
B. 2nd_function
C. _function
D. function123
Select an option to see the answer and solution.
What is the purpose of the def keyword in Python?
A. It is used to define a function
B. It is used to declare a variable
C. It is used to import a module
D. It is used to create a loop
Select an option to see the answer and solution.
What is the purpose of the pass statement in a function?
A. It is a placeholder for future code
B. It returns a value from the function
C. It prints the result on the screen
D. It breaks the loop
Select an option to see the answer and solution.
How is a function defined in Python?
A. Using the def keyword followed by the function name and parameters
B. Using the function keyword
C. Using the define keyword
D. Using the func keyword
Select an option to see the answer and solution.
What does the lambda keyword do when used in a function?
A. It is used to create anonymous functions (lambda functions)
B. It is used to define a named function
C. It is used to import a module
D. It is used to create classes
Select an option to see the answer and solution.
What is the purpose of the global keyword do when used in a function?
A. It allows a variable to be modified outside the current scope
B. It defines a new variable
C. It defines a function
D. It imports a module
Select an option to see the answer and solution.
How can you pass a variable number of keyword arguments to a function in Python?
A. By using the **kwargs syntax
B. By using the *args syntax
C. By using the * symbol
D. By using the ... symbol
Select an option to see the answer and solution.
What is the purpose of the return statement in a function?
A. It specifies the value to be returned from the function
B. It defines the function's name
C. It ends the execution of the function
D. It prints the result on the screen
Select an option to see the answer and solution.
What does the *args syntax in a function definition mean?
A. It allows the function to accept a variable number of arguments as a tuple
B. It is a reserved keyword in Python
C. It specifies the return type of the function
D. It defines a keyword argument
Select an option to see the answer and solution.
What is the purpose of using recursion in a function?
A. It allows a function to call itself
B. It simplifies the syntax of the function
C. It increases the performance of the function
D. It makes the function easier to understand
Select an option to see the answer and solution.
What is the output of the following code:def greet(name): print(f"Hello, {name}!") greet("Alice")
A. Hello, Alice!
B. Hello, name!
C. name
D. "Hello, {name}!"
Select an option to see the answer and solution.
What is the purpose of a function in Python?
A. A function is a reusable block of code that performs a specific task
B. A function is a single line of code
C. A function is a comment in the code
D. A function is a data type in Python
Select an option to see the answer and solution.
What is a variable defined outside a function referred to as?
A. A static variable
B. A global variable
C. A local variable
D. An automatic variable
Select an option to see the answer and solution.
Where are the arguments received from the command line stored?
A. sys.argv
B. os.argv
C. argv
D. none of the mentioned
Select an option to see the answer and solution.
What is the purpose of using the ** symbol in function argument unpacking?
A. It allows a dictionary of arguments to be passed
B. It defines a new variable
C. It specifies the return type of the function
D. It is used to create a loop
Select an option to see the answer and solution.
What will be the output of the following Python code?
def sum(*args):
'''Function returns the sum
of all values'''
r = 0
for i in args:
r += i
return r
print sum.__doc__
print sum(1, 2, 3)
print sum(1, 2, 3, 4, 5)A. 6
15
B. 6
100
C. 123
12345
D. None of the mentioned
Select an option to see the answer and solution.
What will be the output of the following Python code?
min = (lambda x, y: x if x < y else y)
min(101*99, 102*98)A. 9997
B. 9999
C. 9996
D. None of the mentioned
Select an option to see the answer and solution.
The nested list undergoes shallow copy even when the list as a whole undergoes deep copy.
Select an option to see the answer and solution.