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

2/10

Page

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

What will be the output of the following Python code?
x = [34, 56]
print((''.join(list(map(str, x))),))

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = [[0], [1]]
print(len(' '.join(list(map(str, x)))))

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = ['ab', 'cd']
print(len(list(map(list, x))))))

Select an option to see the answer and solution.

What will be the output of the following Python code?
l1=[1, 2, 3, [4]]
l2=list(l1)
id(l1)==id(l2)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def display(b, n):
    while n > 0:
        print(b,end="")
        n=n-1
display('z',3)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo(fname, val):
    print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])

Select an option to see the answer and solution.

What will be the output of the following Python code?
def cube(x):
    return x * x * x      
x = cube(3)    
print x

Select an option to see the answer and solution.

What is the purpose of a docstring in a function?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def f1():
    global x
    x+=1
    print(x)
x=12
print("x")

Select an option to see the answer and solution.

What will be the output of the following Python code?
l1=[10, 20, 30]
l2=l1
id(l1)==id(l2)
 
l2=l1.copy()
id(l1)==id(l2)

Select an option to see the answer and solution.

How are keyword arguments specified in the function heading?

Select an option to see the answer and solution.

Fill in the line of the following Python code for calculating the factorial of a number.
def fact(num):
    if num == 0: 
        return 1
    else:
        return _____________________

Select an option to see the answer and solution.

What will be the output of the following Python code?
def fun(n):
    if (n > 100):
        return n - 5
    return fun(fun(n+11));
 
print(fun(45))

Select an option to see the answer and solution.

What will be the output of the following Python code?
list(map((lambda x:x**2), filter((lambda x:x%2==0), range(10))))

Select an option to see the answer and solution.

What will be the output of the following code:
def my_function(a, b):
  return a / b
result = my_function(4, 2)
print(result)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a = [1, 2, 3, 4, 5]
b = lambda x: (b (x[1:]) + x[:1] if x else []) 
print(b (a))

Select an option to see the answer and solution.

Which of the following statements is false about recursion?

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = ['ab', 'cd']
print(len(list(map(list, x))))

Select an option to see the answer and solution.

Which of these is not true about recursion?

Select an option to see the answer and solution.

What will be the output of the following Python code?
list(map((lambda x:x^2), range(10)))

Select an option to see the answer and solution.