Learn with Yasir

Share Your Feedback

Multiple-Choice Questions (MCQs): Python Functions

  1. What is the output of the following code?
def myfunction(val):
	return val % 4 == 0
print(myfunction (13) or myfunction (8))
  1. What is the output of the following code? Python Quiz #88
  def greet(name="User"):
    return "Hello, " + name
  print(greet("Ahmad"))
A) `Hello, User`  
B) `Hello, Ahmad`  
C) `Hello`  
D) `Error`  
  1. What is the output of the following code? Python Quiz #89
def my_function():
  pass
print(my_function())
- A) `None`  
- B) `0`  
- C) `True`  
- D) `Error`  

  1. What is the output of the following code? Python Quiz #90
    def my_func(a, b=2, c=3):
        return a + b + c
    print(my_func(5, c=4))
    
    • A) 11
    • B) 12
    • C) 10
    • D) Error
  2. Which of the following function calls is invalid for this function definition? [Python Quiz #93]
def my_func(a, b, c=3):
    return a + b + c
  • A) my_func(1, 2)
  • B) my_func(1, 2, 4)
  • C) my_func(a=1, b=2, c=5)
  • D) my_func(1, c=4, b=2, 5)
  1. What is the output of the following code? [Python Quiz #91]
    def change_value(x):
        x = 10
    
    num = 5
    change_value(num)
    print(num)
    
    • A) 5
    • B) 10
    • C) Error
    • D) None
  2. What is the output of the following code? [Python Quiz #96]
def greet(name: str) -> str:
    return "Hello, " + name + "!"
result = greet(5)
print(result)
 - A) Hello, 5!
 - B) TypeError
 - C) None
 - D) Hello, !
  1. What will be the output of this code? [Python Quiz #87]
     def func(x, y=2):
         return x * y
     print(func(3))
    
    • A) 2
    • B) 6
    • C) 3
    • D) Error
  2. What is the main purpose of a function in Python?
  • A) To group a set of related code into a single unit
  • B) To create a new type of data
  • C) To write a program in a single line
  • D) To change the value of global variables
  1. What is the purpose of the return statement in a function in Python?
  • A) To print the output of the function
  • B) To exit the function and return a value
  • C) To execute the function without returning anything
  • D) To stop the function and start a new one
  1. What is the correct way to define a function in Python?
  • A) function my_function():
  • B) def my_function():
  • C) define my_function():
  • D) my_function() {
  1. What happens if you don’t include a return statement in a function?
    • A) The function will return None.
    • B) The function will cause an error.
    • C) The function will return 0.
    • D) The function will return the last variable used.