Welcome to the Python Map, Filter, and Scale back Features MCQs! Map, filter, and cut back are highly effective built-in features in Python for practical programming paradigms. These features help you apply a perform to every factor of a sequence, filter components based mostly on a situation, and cut back a sequence of components to a single worth. These questions will take a look at your understanding of methods to use map, filter, and cut back features in Python, together with their syntax, goal, and examples. Every query is multiple-choice, with just one appropriate reply. Take your time to fastidiously learn every query and select the best choice. Let’s discover the world of Python map, filter, and cut back features collectively!

30+ MCQs on Python Map, Filter and Scale back Features
Q1. What’s the goal of the map()
perform in Python?
a) To filter components of a sequence based mostly on a given perform
b) To use a perform to each merchandise in an iterable and return an inventory of the outcomes
c) To scale back an iterable right into a single cumulative worth
d) To return a subset of components from an iterable based mostly on a situation
Reply: b
Rationalization: The map()
perform in Python applies a given perform to each merchandise in an iterable and returns an inventory of the outcomes.
Q2. Which of the next is an accurate syntax for the map()
perform in Python?
a) map(perform, sequence)
b) map(sequence, perform)
c) map(sequence)(perform)
d) map(perform)(sequence)
Reply: a
Rationalization: The proper syntax for the map()
perform is map(perform, sequence)
the place perform
is the perform to be utilized and sequence
is the iterable.
Q3. What does the filter()
perform in Python do?
a) Applies a perform to each merchandise in an iterable and returns a single cumulative worth
b) Filters out components of an iterable based mostly on a given perform
c) Returns a subset of components from an iterable based mostly on a situation
d) Maps a perform to each merchandise in an iterable and returns an inventory of the outcomes
Reply: c
Rationalization: The filter()
perform in Python returns a subset of components from an iterable based mostly on a situation specified by a perform.
This fall. Which of the next is an accurate syntax for the filter()
perform in Python?
a) filter(perform, sequence)
b) filter(sequence, perform)
c) filter(sequence)(perform)
d) filter(perform)(sequence)
Reply: a
Rationalization: The proper syntax for the filter()
perform is filter(perform, sequence)
the place perform
is the filtering perform and sequence
is the iterable.
Q5. What does the cut back()
perform in Python do?
a) Reduces an iterable right into a single cumulative worth utilizing a perform
b) Applies a perform to each merchandise in an iterable and returns an inventory of the outcomes
c) Filters out components of an iterable based mostly on a given perform
d) Maps a perform to each merchandise in an iterable and returns an inventory of the outcomes
Reply: a
Rationalization: The cut back()
perform in Python reduces an iterable right into a single cumulative worth by making use of a perform repeatedly to pairs of things.
Q6. Which module is required to make use of the cut back()
perform in Python?
a) math
b) functools
c) itertools
d) operator
Reply: b
Rationalization: The cut back()
perform in Python is a part of the functools
module, so import functools
is required to make use of it.
Q7. What would be the output of the next code?
from functools import cut back
def multiply(x, y):
return x * y
numbers = [1, 2, 3, 4, 5]
outcome = cut back(multiply, numbers)
print(outcome)
a) 15
b) 120
c) 30
d) 10
Reply: b
Rationalization: The code will output 120
as a result of cut back()
applies the multiply
perform cumulatively to the objects of the numbers
record.
Q8. What is going to the next code snippet do?
numbers = [1, 2, 3, 4, 5]
squared = map(lambda x: x**2, numbers)
a) Creates an inventory of squares of every quantity in numbers
b) Filters out even numbers from numbers
c) Reduces numbers
right into a single cumulative worth
d) Raises a syntax error
Reply: a
Rationalization: The code creates a map object squared
containing the squares of every quantity within the numbers
record.
Q9. Which of the next statements concerning the lambda
perform in Python is true?
a) The lambda
perform can include a number of expressions.
b) The lambda
perform can have a return assertion.
c) The lambda
perform can have default arguments.
d) The lambda
perform can solely have a single expression.
Reply: d
Rationalization: The lambda
perform in Python can solely have a single expression.
Q10. What would be the output of the next code?
def even_check(num):
if num % 2 == 0:
return True
else:
return False
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_numbers = filter(even_check, numbers)
print(record(even_numbers))
a) [1, 3, 5, 7, 9]
b) [2, 4, 6, 8, 10]
c) [True, False, True, False, True, False, True, False, True, False]
d) [2, 4, 6, 8]
Reply: b
Rationalization: The code filters out even numbers from the numbers
record utilizing the even_check
perform and prints the ensuing record.
Q11. Which of the next is equal to the map()
perform?
a) Listing comprehension
b) Generator expression
c) Iterator
d) Filter perform
Reply: a
Rationalization: Listing comprehension in Python is equal to the map()
perform as it may be used to carry out comparable duties of making use of a perform to each merchandise in an iterable.
Q12. What would be the output of the next code?
def add(a, b):
return a + b
numbers1 = [1, 2, 3, 4]
numbers2 = [5, 6, 7, 8]
sums = map(add, numbers1, numbers2)
print(record(sums))
a) [6, 8, 10, 12]
b) [1, 2, 3, 4, 5, 6, 7, 8]
c) [15, 18, 21, 24]
d) [1, 5, 2, 6, 3, 7, 4, 8]
Reply: a
Rationalization: The code creates a map
object sums
that provides corresponding components from numbers1
and numbers2
, leading to [6, 8, 10, 12]
.
Q13. What does the operator
module present in Python?
a) Features comparable to built-in operations
b) Features for creating iterators
c) Features for sorting lists
d) Features for mathematical operations
Reply: a
Rationalization: The operator
module in Python supplies features that correspond to built-in operations, making it helpful for map()
and cut back()
features.
Q14. What is going to the next code snippet do?
def is_positive(num):
return num > 0
numbers = [-1, 3, -5, 7, -9]
positive_nums = filter(is_positive, numbers)
a) Create an inventory of constructive numbers from numbers
b) Create an inventory of destructive numbers from numbers
c) Create an inventory of even numbers from numbers
d) Create an inventory of all numbers from numbers
Reply: a
Rationalization: The code filters out constructive numbers from the numbers
record utilizing the is_positive
perform.
Q15. Which perform can be utilized to mix components of an iterable utilizing a specified perform and cut back it to a single worth?
a) apply()
b) be a part of()
c) cut back()
d) mix()
Reply: c
Rationalization: The cut back()
perform in Python is used to mix components of an iterable utilizing a specified perform and cut back it to a single worth.
Q16. What would be the output of the next code?
from functools import cut back
numbers = [10, 20, 30, 40, 50]
complete = cut back(lambda x, y: x + y, numbers)
print(complete)
a) 150
b) 100
c) 200
d) 250
Reply: a
Rationalization: The code will output 150
as a result of cut back()
provides all of the numbers within the numbers
record collectively.
Q17. Which of the next statements concerning the map()
perform in Python is true?
a) map()
all the time returns an inventory.
b) map()
can solely be used with features that take a single argument.
c) map()
can be utilized with a number of iterables.
d) map()
modifies the unique iterable.
Reply: c
Rationalization: The map()
perform in Python can be utilized with a number of iterables, making use of the given perform to corresponding objects.
Q18. What is going to the next code snippet do?
numbers = [1, 2, 3, 4, 5]
squared = map(lambda x: x**2, numbers)
a) Create an inventory of squares of every quantity in numbers
b) Create an inventory of cubes of every quantity in numbers
c) Create an inventory of even numbers from numbers
d) Create an inventory of all numbers from numbers
Reply: a
Rationalization: The code creates a map object squared
containing the squares of every quantity within the numbers
record.
Q19. Which perform in Python can be utilized to filter an inventory of components based mostly on a given situation?
a) cut back()
b) filter()
c) map()
d) apply()
Reply: b
Rationalization: The filter()
perform in Python is used to filter an inventory of components based mostly on a given situation.
Q20. What would be the output of the next code?
def is_even(num):
return num % 2 == 0
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_numbers = filter(is_even, numbers)
print(record(even_numbers))
a) [2, 4, 6, 8, 10]
b) [1, 3, 5, 7, 9]
c) [True, False, True, False, True, False, True, False, True, False]
d) [2, 4, 6, 8]
Reply: a
Rationalization: The code filters out even numbers from the numbers
record utilizing the is_even
perform and prints the ensuing record.
Q21. Which of the next features can be utilized to use a given perform to each merchandise of an iterable?
a) cut back()
b) map()
c) filter()
d) apply()
Reply: b
Rationalization: The map()
perform in Python is used to use a given perform to each merchandise of an iterable.
Q22. What would be the output of the next code?
from functools import cut back
numbers = [1, 2, 3, 4, 5]
product = cut back(lambda x, y: x * y, numbers)
print(product)
a) 120
b) 30
c) 15
d) 10
Reply: a
Rationalization: The code will output 120
as a result of cut back()
multiplies all of the numbers within the numbers
record collectively.
Q23. Which of the next is an accurate syntax for the cut back()
perform in Python?
a) cut back(sequence, perform)
b) cut back(perform, sequence)
c) cut back(sequence)(perform)
d) cut back(perform)(sequence)
Reply: b
Rationalization: The proper syntax for the cut back()
perform is cut back(perform, sequence)
the place perform
is the lowering perform and sequence
is the iterable.
Q24. What is going to the next code snippet do?
numbers = [10, 20, 30, 40, 50]
doubled = map(lambda x: x * 2, numbers)
a) Create an inventory of doubled numbers from numbers
b) Create an inventory of halved numbers from numbers
c) Create an inventory of even numbers from numbers
d) Create an inventory of all numbers from numbers
Reply: a
Rationalization: The code creates a map object doubled
containing the doubled values of every quantity within the numbers
record.
Q25. Which perform can be utilized to use a perform to every factor of an iterable and return an inventory of outcomes?
a) apply()
b) map()
c) filter()
d) cut back()
Reply: b
Rationalization: The map()
perform in Python applies a perform to every factor of an iterable and returns an inventory of outcomes.
Q26. What would be the output of the next code?
def is_vowel(char):
vowels="aeiouAEIOU"
return char in vowels
chars = ['a', 'b', 'c', 'd', 'e', 'F', 'G', 'H', 'I', 'j']
filtered_chars = filter(is_vowel, chars)
print(record(filtered_chars))
a) [‘a’, ‘e’, ‘F’, ‘I’]
b) [‘a’, ‘e’, ‘I’]
c) [‘a’, ‘e’, ‘A’, ‘E’, ‘I’]
d) [‘a’, ‘e’]
Reply: b
Rationalization: The code filters out the vowels from the chars
record utilizing the is_vowel
perform and prints the ensuing record.
Q27. What does the operator
module present in Python?
a) Features comparable to built-in operations
b) Features for creating iterators
c) Features for sorting lists
d) Features for mathematical operations
Reply: a
Rationalization: The operator
module in Python supplies features that correspond to built-in operations, making it helpful for map()
and cut back()
features.
Q28. What would be the output of the next code?
import functools
numbers = [1, 2, 3, 4, 5]
sums = functools.cut back(lambda x, y: x + y, numbers)
print(sums)
a) 15
b) 10
c) 20
d) 25
Reply: a
Rationalization: The code will output 15
as a result of cut back()
provides all of the numbers within the numbers
record collectively.
Q29. What would be the output of the next code?
def dice(num):
return num ** 3
numbers = [1, 2, 3, 4, 5]
cubed = map(dice, numbers)
print(record(cubed))
a) [1, 8, 27, 64, 125]
b) [2, 4, 6, 8, 10]
c) [1, 2, 3, 4, 5]
d) [3, 6, 9, 12, 15]
Reply: a
Rationalization: The code will output [1, 8, 27, 64, 125]
as a result of map()
applies the dice
perform to every factor in numbers
.
Q30. What would be the output of the next code?
def sq.(num):
return num * num
numbers = [1, 2, 3, 4, 5]
squared = map(sq., numbers)
print(record(squared))
a) [1, 4, 9, 16, 25]
b) [2, 4, 6, 8, 10]
c) [1, 3, 5, 7, 9]
d) [1, 2, 3, 4, 5]
Reply: a
Rationalization: The code will output [1, 4, 9, 16, 25]
as a result of map()
applies the sq.
perform to every factor in numbers
.
Q31. What would be the output of the next code?
from functools import cut back
def multiply(x, y):
return x * y
numbers = [1, 2, 3, 4, 5]
product = cut back(multiply, numbers, 10)
print(product)
a) 150
b) 120
c) 100
d) 200
Reply: b
Rationalization: The code will output 120
as a result of cut back()
multiplies all of the numbers within the numbers
record collectively beginning with an preliminary worth of 10.
Congratulations on finishing the Python Map, Filter, and Scale back Features MCQs! Map, filter, and cut back features are highly effective instruments for practical programming in Python, permitting you to use transformations and operations to sequences of components. By mastering these features, you achieve the flexibility to write down concise and environment friendly code for knowledge manipulation duties. Preserve working towards and experimenting with map, filter, and cut back features to turn into proficient in utilizing them successfully. You probably have any questions or wish to delve deeper into any subject, don’t hesitate to proceed your studying journey. Joyful coding!
You can too enroll in our free Python Course Immediately!
Learn our extra articles associated to MCQs in Python: