Vidyalelo
Python · all questions

Functions in Python
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

182

Questions

1/10

Page

Pick an option on a question to see the right answer and solution.

What does the return statement in a function do?

Select an option to see the answer and solution.

How can you make a parameter optional in a Python function?

Select an option to see the answer and solution.

Which of the following is NOT a valid function name in Python?

Select an option to see the answer and solution.

What is the purpose of the def keyword in Python?

Select an option to see the answer and solution.

What is the purpose of the pass statement in a function?

Select an option to see the answer and solution.

How is a function defined in Python?

Select an option to see the answer and solution.

What does the lambda keyword do when used in a function?

Select an option to see the answer and solution.

What is the purpose of the global keyword do when used in a function?

Select an option to see the answer and solution.

How can you pass a variable number of keyword arguments to a function in Python?

Select an option to see the answer and solution.

What is the purpose of the return statement in a function?

Select an option to see the answer and solution.

What does the *args syntax in a function definition mean?

Select an option to see the answer and solution.

What is the purpose of using recursion in a function?

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")

Select an option to see the answer and solution.

What is the purpose of a function in Python?

Select an option to see the answer and solution.

What is a variable defined outside a function referred to as?

Select an option to see the answer and solution.

Where are the arguments received from the command line stored?

Select an option to see the answer and solution.

What is the purpose of using the ** symbol in function argument unpacking?

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)

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)

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.