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

9/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?
def foo(k):
    k[0] = 1
q = [0]
foo(q)
print(q)

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=[2, 3, [4, 5]]
l2=l.copy()
l2[0]=88
l
l2

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which is the most appropriate definition for recursion?

Select an option to see the answer and solution.

What will be the output of the following Python code?
x=1
def cg():
	global x
	x=x+1	
cg()
x

Select an option to see the answer and solution.

What will be the output of the following Python code?
e="butter"
def f(a): print(a)+e
f("bitter")

Select an option to see the answer and solution.

What will be the output of the following Python code?
def change(one, *two):
   print(type(two))
change(1,2,3,4)

Select an option to see the answer and solution.

In . . . . . . . . copy, the base address of the objects are copied. In . . . . . . . . copy, the base address of the objects are not copied.

Select an option to see the answer and solution.

What is called when a function is defined inside a class?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def to_upper(k):
    return k.upper()
x = ['ab', 'cd']
print(list(map(to_upper, x)))

Select an option to see the answer and solution.

What will be the output of the following Python code?
def writer():
	title = 'Sir'
	name = (lambda x:title + ' ' + x)
	return name
 
who = writer()
who('Arthur')

Select an option to see the answer and solution.

Which of the following numbers will not be a part of the output list of the following Python code?
def sf(a):
    return a%3!=0 and a%5!=0
m=filter(sf, range(1, 31))
print(list(m))

Select an option to see the answer and solution.

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

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 Python code?
l1=[1, 2, 3, (4)]
l2=l1.copy()
l2
l1

Select an option to see the answer and solution.

What are the two main types of functions?

Select an option to see the answer and solution.

What is the output of the following code:
def greet(name="User"):
  print(f"Hello, {name}!")
greet()

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the output of the following code:
def my_function(a, b):
  return a * b
result = my_function(4, 0)
print(result)

Select an option to see the answer and solution.