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

8/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 = ['ab', 'cd']
print(list(map(list, x)))

Select an option to see the answer and solution.

What will be the output of the following Python code?
def change(i = 1, j = 2):
    i = i + j
    j = j + 1
    print(i, j)
change(j = 1, i = 2)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def ram(x):
    print(x+1)
x=-2
x=4
ram(12)

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = 50
def func(x):
    print('x is', x)
    x = 2
    print('Changed local x to', x)
func(x)
print('x is now', x)

Select an option to see the 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 is the output of the following code:
def multiply(a, b=2):
  return a * b
result = multiply(4)
print(result)

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = 5 
def f1():
    global x
    x = 4
def f2(a,b):
    global x
    return a+b+x
f1()
total = f2(1,2)
print(total)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def f1():
    x=15
    print(x)
x=12
f1()

Select an option to see the answer and solution.

What will be the output of the following Python code?
def find(a, **b):
   print(type(b))
find('letters',A='1',B='2')

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo():
    return total + 1
total = 0
print(foo())

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What will be the output of the following Python code?
i=0
def change(i):
   i=i+1
   return i
change(1)
print(i)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

Select an option to see the answer and solution.

Which of the following refers to mathematical function?

Select an option to see the answer and solution.

What will be the output of the following Python code?
a=10
globals()['a']=25
print(a)

Select an option to see the answer and solution.

Recursion and iteration are the same programming approach.

Select an option to see the answer and solution.

What will be the output of the following Python code?
def a(b):
    b = b + [5]
 
c = [1, 2, 3, 4]
a(c)
print(len(c))

Select an option to see the answer and solution.

What is the length of sys.argv?

Select an option to see the answer and solution.

What will be the output of the following Python code and state the type of copy that is depicted?
l1=[2, 4, 6, 8]
l2=[1, 2, 3]
l1=l2
l2

Select an option to see the answer and solution.

What will be the output of the following Python code?
elements = [0, 1, 2]
def incr(x):
    return x+1
print(list(map(incr, elements)))

Select an option to see the answer and solution.