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

6/10

Page

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

How can you pass multiple arguments to a function as a tuple?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def maximum(x, y):
    if x > y:
        return x
    elif x == y:
        return 'The numbers are equal'
    else:
        return y
 
print(maximum(2, 3))

Select an option to see the answer and solution.

Which of the following is a feature of DocString?

Select an option to see the answer and solution.

In . . . . . . . . copy, the modification done on one list affects the other list. In . . . . . . . . copy, the modification done on one list does not affect the other list.

Select an option to see the answer and solution.

What will be the output of the following Python code?
l1=[10, 20, 30, [40]]
l2=copy.deepcopy(l1)
l1[3][0]=90
l1
l2

Select an option to see the answer and solution.

What will be the output of the following Python code?
y = 6
z = lambda x: x * y
print z(8)

Select an option to see the answer and solution.

What will be the output of the following Python code?
L = [lambda x: x ** 2,
         lambda x: x ** 3,
         lambda x: x ** 4]
 
for f in L:
	print(f(3))

Select an option to see the answer and solution.

Which are the advantages of functions in python?

Select an option to see the answer and solution.

Lambda is a statement.

Select an option to see the answer and solution.

What will be the output of the following Python code?
def func(a, b=5, c=10):
    print('a is', a, 'and b is', b, 'and c is', c)
 
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=[1, -2, -3, 4, 5]
def f1(x):
    return x<2
m1=filter(f1, l)
print(list(m1))

Select an option to see the answer and solution.

How can you pass a list to a function as an argument?

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = 'abcd'
print(list(map(list, x)))

Select an option to see the answer and solution.

How are default arguments specified in the function heading?

Select an option to see the answer and solution.

How are variable length arguments specified in the function heading?

Select an option to see the answer and solution.

Which type of copy is shown in the following python code?
l1=[[10, 20], [30, 40], [50, 60]]
ls=list(l1)
ls
[[10, 20], [30, 40], [50, 60]]

Select an option to see the answer and solution.

What will be the output of the following Python code?
odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
    if odd(i):
        continue
    else:
        break

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = 1234
print(list(map(list, x)))

Select an option to see the answer and solution.

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)
print(result)

Select an option to see the answer and solution.

What happens if a local variable exists with the same name as the global variable you want to access?

Select an option to see the answer and solution.