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

7/10

Page

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

Which of these is false about recursion?

Select an option to see the answer and solution.

What is the purpose of using the * symbol in function argument packing?

Select an option to see the answer and solution.

What is the type of each element in sys.argv?

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=[]
def convert(b):
    if(b==0):
        return l
    dig=b%2
    l.append(dig)
    convert(b//2)
convert(6)
l.reverse()
for i in l:
    print(i,end="")

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
    if f(l[i]):
        del l[i]
        print(i)

Select an option to see the answer and solution.

The single line equivalent of the following Python code?
l=[1, 2, 3, 4, 5]
def f1(x):
    return x<0
m1=filter(f1, l)
print(list(m1))

Select an option to see the answer and solution.

What will be the output of the following Python code?
def C2F(c):
    return c * 9/5 + 32
print C2F(100)
print C2F(0)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def say(message, times = 1):
    print(message * times)
say('Hello')
say('World', 5)

Select an option to see the answer and solution.

What will be the output of the following Python code?
f=lambda x:bool(x%2)
print(f(20), f(21))

Select an option to see the answer and solution.

What will be the output of the following Python code?
import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo(i, x=[]):
    x.append(i)
    return x
for i in range(3):
    print(foo(i))

Select an option to see the answer and solution.

What does the nonlocal keyword do when used in a function?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def f(x):
    print("outer")
    def f1(a):
        print("inner")
        print(a,x)
f(3)
f1(1)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))

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 can you define a function that accepts an arbitrary number of keyword arguments?

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.

Which of the following is the use of function in python?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the output of the following code:
def power(x, n=2):
  return x ** n
result = power(3)
print(result)

Select an option to see the answer and solution.