Python Programming - MCQ Practice Questions
Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.
188 questions | 100% Free
What will be the output of the following code?
def greet(name, msg='Hello'):
return f'{msg}, {name}!'
print(greet('Alice'))
print(greet('Bob', 'Hi'))
What will be the output of the following code?
def func(*args, **kwargs):
print(len(args), len(kwargs))
func(1, 2, 3, a=4, b=5)
Which of the following statements about lambda functions in Python is CORRECT?
What will be the output of the following code?
def outer():
x = 10
def inner():
nonlocal x
x += 5
inner()
return x
print(outer())
What is the purpose of the __init__.py file in a Python package directory?
What will be the output of the following code?
def add(a, b):
return a + b
result = add
print(result(3, 4))
Which of the following correctly imports only the sqrt function from the math module?
What will be the output of the following code?
def counter():
count = 0
def increment():
nonlocal count
count += 1
return count
return increment
c = counter()
print(c())
print(c())
print(c())
What will be the output of the following code?
import math as m
print(m.floor(4.7))
print(m.ceil(4.2))
What will be the output of the following code?
def apply(func, value):
return func(value)
result = apply(lambda x: x ** 2, 5)
print(result)