Software Development Exam  >  Software Development Tests  >  Basics of Python  >  Test: Functions - 2 - Software Development MCQ

Test: Functions - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test Basics of Python - Test: Functions - 2

Test: Functions - 2 for Software Development 2024 is part of Basics of Python preparation. The Test: Functions - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Functions - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Functions - 2 below.
Solutions of Test: Functions - 2 questions in English are available as part of our Basics of Python for Software Development & Test: Functions - 2 solutions in Hindi for Basics of Python course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Functions - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study Basics of Python for Software Development Exam | Download free PDF with solutions
Test: Functions - 2 - Question 1

What is a function in Python?

Detailed Solution for Test: Functions - 2 - Question 1

Functions in Python are defined using the def keyword followed by a block of code. They are used to group related code and perform specific tasks. Functions can accept input parameters, perform operations, and return a value using the return statement.

Test: Functions - 2 - Question 2

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

Detailed Solution for Test: Functions - 2 - Question 2

The return statement is used to specify the value that a function should return. It also terminates the execution of the function, meaning that any code after the return statement will not be executed.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Functions - 2 - Question 3

What are local variables in Python functions?

Detailed Solution for Test: Functions - 2 - Question 3

Local variables in Python are variables that are defined within a function and can only be accessed within that function. They have a limited scope and are not accessible outside of the function.

Test: Functions - 2 - Question 4

What is recursion in Python?

Detailed Solution for Test: Functions - 2 - Question 4

Recursion in programming refers to a technique where a function calls itself to solve a problem. This can be useful for solving problems that can be broken down into smaller subproblems.

Test: Functions - 2 - Question 5

What is the purpose of an anonymous function in Python?

Detailed Solution for Test: Functions - 2 - Question 5

Anonymous functions in Python, also known as lambda functions, are functions that are defined without a name. They are typically used for simple tasks and can be created using the lambda keyword.

Test: Functions - 2 - Question 6

What will be the output of the following code?
def multiply(a, b):
    return a * b

result = multiply(4, 5)
print(result)

Detailed Solution for Test: Functions - 2 - Question 6

The multiply function takes two arguments, a and b, and returns their product. When the function is called with the arguments 4 and 5, it returns 20, which is then printed.

Test: Functions - 2 - Question 7

What will be the output of the following code?
def greet(name):
    print("Hello, " + name + "!")

greet("Alice")

Detailed Solution for Test: Functions - 2 - Question 7

The greet function takes a parameter name and prints a greeting message with the provided name. When the function is called with the argument "Alice", it prints "Hello, Alice!".

Test: Functions - 2 - Question 8

What will be the output of the following code?
def calculate_average(numbers):
    total = sum(numbers)
    avg = total / len(numbers)
    return avg

scores = [85, 90, 92, 88, 95]
average_score = calculate_average(scores)
print(average_score)

Detailed Solution for Test: Functions - 2 - Question 8

The calculate_average function takes a list of numbers as input, calculates the average of the numbers, and returns the result. In this case, the function is called with the list [85, 90, 92, 88, 95], and it returns the average score of 88.5, which is then printed.

Test: Functions - 2 - Question 9

What will be the output of the following code?
def greet():
    message = "Hello, world!"
    print(message)

greet()
print(message)

Detailed Solution for Test: Functions - 2 - Question 9

The greet function defines a local variable message and prints its value. However, when the print(message) statement is executed outside of the function, it throws a NameError because the variable message is not defined in the global scope.

Test: Functions - 2 - Question 10

What will be the output of the following code?
def power(base, exponent=2):
    return base ** exponent

result1 = power(3)
result2 = power(2, 4)
result3 = power(exponent=3, base=5)

print(result1, result2, result3)

Detailed Solution for Test: Functions - 2 - Question 10

The power function is defined with two parameters, base and exponent, with a default value of 2 for exponent. In this case, result1 is assigned the value of power(3) which is 9, result2 is assigned the value of power(2, 4) which is 16, and result3 is assigned the value of power(base=5, exponent=3) which is 125. These values are then printed.

Test: Functions - 2 - Question 11

What will be the output of the following code?
x = 5

def update_global():
    global x
    x = 10

update_global()
print(x)

Detailed Solution for Test: Functions - 2 - Question 11

The global variable x is updated inside the update_global function using the global keyword. When the function is called, the value of x is changed to 10. Therefore, when print(x) is executed, it prints the updated value, which is 10.

Test: Functions - 2 - Question 12

What will be the output of the following code?
def outer_function(x):
    def inner_function(y):
        nonlocal x
        x += y
        return x
    return inner_function

add_5 = outer_function(5)
result = add_5(3)

print(result)

Detailed Solution for Test: Functions - 2 - Question 12

The outer_function defines a local variable x and an inner function inner_function that modifies x by adding y to it. The outer_function returns the inner_function. When outer_function(5) is called, it returns the inner_function, which is assigned to add_5. When add_5(3) is called, it adds 3 to the current value of x (which is 5) and returns 8.

Test: Functions - 2 - Question 13

What will be the output of the following code?
def function_with_args(*args):
    return len(args)

result = function_with_args(1, 2, 3, 4, 5)

print(result)

Detailed Solution for Test: Functions - 2 - Question 13

The function_with_args function accepts variable-length arguments using *args. In this case, it is called with the arguments 1, 2, 3, 4, and 5. The len function is used to calculate the length of args, which is 5, and it is returned and printed.

Test: Functions - 2 - Question 14

What will be the output of the following code?
def function_with_kwargs(**kwargs):
    return kwargs

result = function_with_kwargs(a=1, b=2, c=3)

print(result)

Detailed Solution for Test: Functions - 2 - Question 14

The function_with_kwargs function accepts variable-length keyword arguments using **kwargs. In this case, it is called with the keyword arguments a=1, b=2, and c=3. The kwargs dictionary stores these keyword arguments, and it is returned and printed.

Test: Functions - 2 - Question 15

What will be the output of the following code?
def calculate_total(*numbers):
    total = 0
    for num in numbers:
        total += num
    return total

result = calculate_total(1, 2, 3, 4)

print(result)

Detailed Solution for Test: Functions - 2 - Question 15

The calculate_total function accepts variable-length arguments using *numbers. In this case, it is called with the arguments 1, 2, 3, and 4. The function iterates over the numbers and calculates the sum, which is 10. The sum is then returned and printed.

49 videos|38 docs|18 tests
Information about Test: Functions - 2 Page
In this test you can find the Exam questions for Test: Functions - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Functions - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

49 videos|38 docs|18 tests
Download as PDF

Top Courses for Software Development