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

5/10

Page

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

What is a variable defined inside a function referred to as?

Select an option to see the answer and solution.

What will be the output of the following Python code?
x = [[0], [1]]
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?
def foo(i, x=[]):
    x.append(x.append(i))
    return x
for i in range(3):
    y = foo(i)
print(y)

Select an option to see the answer and solution.

What will be the output of the following Python code?
def foo(k):
    k = [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?
x = [12, 34]
print(len(''.join(list(map(int, x)))))

Select an option to see the answer and solution.

On assigning a value to a variable inside a function, it automatically becomes a global variable.

Select an option to see the answer and solution.

Which of the following data structures is returned by the functions globals() and locals()?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def power(x, y=2):
    r = 1
    for i in range(y):
       r = r * x
    return r
print power(3)
print power(3, 3)

Select an option to see the answer and solution.

Does Lambda contains return statements?

Select an option to see the answer and solution.

What will be the output of the following Python code?
l=[-2, 4]
m=map(lambda x:x*2, l)
print(m)

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the value stored in sys.argv[0]?

Select an option to see the answer and solution.

What will be the output of the following Python code?
def sayHello():
    print('Hello World!') 
sayHello() 
sayHello()

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]
m=map(lambda x:2**x, l)
print(list(m))

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]
print(functools.reduce(lambda x,y:x*y,l))

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the type of sys.argv?

Select an option to see the answer and solution.

What will be the output of the following Python code?
m=reduce(lambda x: x-3 in range(4, 10))
print(list(m))

Select an option to see the answer and solution.

Read the following Python code carefully and point out the global variables?
y, z = 1, 2
def f():
    global x
    x = y+z

Select an option to see the answer and solution.