Search Tutorials


Python Functions MCQ Questions and Answers | JavaInUse

Python Functions MCQ Questions and Answers

Q. What is a function in Python used for?

A. To structure and organize code
B. To enable code reuse
C. To execute code multiple times
D. All of the above

Q. How do you define a function in Python?

A. Using the `function` keyword
B. Using the `def` keyword
C. Using the `create_function` method
D. None of the above

Q. What is the difference between a function and a method in Python?

A. A function is a standalone block of code, while a method is associated with an object
B. A function can have any name, while a method must start with `self`
C. A function can have multiple parameters, while a method can only have one
D. There is no difference

Q. What are parameters in a function?

A. Variables used to pass data into a function
B. Variables used to store return values
C. Variables used to control flow
D. None of the above

Q. What is a return value in a function?

A. The value produced by a function
B. The value passed into a function
C. The value stored in a variable within a function
D. None of the above

Q. What happens if a function does not have a return statement?

A. It returns None
B. It returns an error
C. It returns the last executed statement
D. It continues executing indefinitely

Q. What is a local variable in a function?

A. A variable defined and used within a function
B. A variable defined outside and used within a function
C. A variable defined within a function and accessible globally
D. None of the above

Q. What is a global variable in a function?

A. A variable defined in a function and accessible globally
B. A variable defined outside a function and accessible within
C. A variable defined in a function and accessible to other functions
D. None of the above

Q. How can you access a global variable from within a function?

A. Using the `global` keyword
B. Passing it as an argument
C. Defining it inside the function
D. None of the above

Q. What is function recursion?

A. When a function calls itself
B. When a function calls another function
C. When a function returns a value
D. None of the above

Q. What does the `*args` syntax in function definitions allow for?

A. Passing a variable number of arguments
B. Specifying default argument values
C. Unpacking arguments from a list
D. All of the above

Q. How can you pass a list of values as arguments to a function?

A. Using the `*args` syntax
B. Using the `**` syntax
C. Passing the list as a single argument
D. None of the above

Q. How can you pass keyword arguments to a function?

A. Using the `**` syntax
B. Using the `*args` syntax
C. Passing a dictionary as an argument
D. None of the above

Q. What is a lambda function?

A. A small, anonymous function defined with `lambda`
B. A function returning a lambda expression
C. A function taking a lambda expression as an argument
D. None of the above

Q. How can you create a function that takes a variable number of arguments?

A. Using the `*args` syntax
B. Using the `**` syntax
C. Defining with a list of arguments
D. None of the above