Which of the following statements best describes a function in Python?
What is the purpose of using the "return" statement in a function?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which of the following types of functions does not return a value?
What is the difference between actual parameters and formal parameters in a function?
What will be the output of the following code?
def add_numbers(a, b): return a + b
result = add_numbers(3, 7) print(result)
What will be the output of the following code?
def greet(name="Guest"):
print("Hello, " + name + "!")
greet("Alice") greet()
What will be the output of the following code?
x = 5
def change_x():
global x
x = 10
change_x()
print(x)
What will be the output of the following code?
def square(number):
return number ** 2
result = square(square(2))
print(result)
What will be the output of the following code?
def multiply(a, b=2):
return a * b
result = multiply(5, 3)
print(result)
What will be the output of the following code?
def increment(x):
x += 1
return x
def square(x):
x = increment(x)
return x ** 2
result = square(3)
print(result)
What will be the output of the following code?
def outer_function():
x = 10
def inner_function():
nonlocal x
x += 5
print(x)
inner_function()
print(x)
outer_function()
What will be the output of the following code?
def power(x, n):
if n == 0:
return 1
elif n % 2 == 0:
return power(x, n // 2) ** 2
else:
return x * power(x, n - 1)
result = power(2, 4)
print(result)
What will be the output of the following code?
def multiply(a, *args):
result = a
for num in args:
result *= num
return result
result = multiply(2, 3, 4, 5)
print(result)
What will be the output of the following code?
def outer():
x = 5
def inner():
nonlocal x
x = 10
inner()
print(x)
outer()
49 videos|38 docs|18 tests
|
49 videos|38 docs|18 tests
|