Functions in Python are reusable blocks of code designed to perform a specific task, promoting code modularity, readability, and DRY (Don’t Repeat Yourself) principles. Defined using the def keyword, Python functions support versatile parameter passing including positional arguments, keyword arguments, default parameter values, variable length positional arguments (*args), and variable-length keyword arguments (**kwargs). Python evaluates variable lookup using the LEGB (Local, Enclosing, Global, Built-in) scope hierarchy. Furthermore, Python treats functions as first-class objects, enabling anonymous functions (lambda), higher order function mapping (map, filter, reduce), decorators, and recursive problem solving. This 25-question MCQ quiz evaluates core function mechanics, offering detailed explanations to deepen your proficiency.
Python Functions MCQs
1 min read
Correct Answer: b) def
Explanation:
In Python, the 'def' keyword is used to begin a function definition, followed by the function name, parentheses, and a colon.
Correct Answer: c) None
Explanation:
If no return statement is encountered or an empty return is used, Python implicitly returns the None object.
Correct Answer: b) To document the purpose and usage of the function
Explanation:
A docstring is a string literal that occurs as the first statement in a function definition, used to document its behavior.
Correct Answer: b) func.__doc__
Explanation:
The docstring of a function is stored in its special `__doc__` attribute.
Correct Answer: a) *args
Explanation:
The `*args` parameter collects extra positional arguments passed to the function into a single tuple.
Correct Answer: c) Tuple
Explanation:
Positional arguments gathered via `*args` are packed into an immutable tuple.
Correct Answer: b) **kwargs
Explanation:
The `**kwargs` parameter syntax gathers arbitrary keyword arguments into a dictionary.
Correct Answer: b) Dictionary
Explanation:
Keyword arguments collected using `**kwargs` are stored as key-value pairs inside a standard dictionary.
Correct Answer: b) Hello Guest
Explanation:
When an argument is omitted during a call, Python falls back to using the parameter's default value ('Guest').
Correct Answer: b) Python raises a SyntaxError
Explanation:
Non-default parameters must always precede default parameters in a function signature.
Correct Answer: b) An anonymous function defined with a single expression
Explanation:
Lambda functions are small, anonymous inline functions created using the `lambda` keyword.
Correct Answer: a) lambda x: x ** 3
Explanation:
The syntax for a lambda function is `lambda arguments: expression`, evaluating and returning the result without an explicit `return` keyword.
Correct Answer: a) 20
Explanation:
The lambda expression is defined and immediately called with positional parameters `4` and `5`, returning `4 * 5 = 20`.
Correct Answer: b) A function that calls itself in its definition
Explanation:
A recursive function calls itself directly or indirectly to divide a problem into smaller instances.
Correct Answer: b) A base case
Explanation:
A base case provides a stopping condition that resolves without making further recursive calls.
Correct Answer: b) RecursionError
Explanation:
Python raises a `RecursionError` when maximum recursion depth is reached to prevent stack overflow.
Correct Answer: b) sys
Explanation:
The `sys` module provides `sys.getrecursionlimit()` and `sys.setrecursionlimit()` to manage call stack depth.
Correct Answer: b) global
Explanation:
The `global` keyword declares that a variable belongs to the global (module-level) scope.
Correct Answer: b) nonlocal
Explanation:
The `nonlocal` keyword allows binding to variables declared in enclosing outer functions (excluding global scope).
Correct Answer: a) LEGB
Explanation:
Python searches scopes in order: Local, Enclosing, Global, and Built-in (LEGB).
Correct Answer: b) 10
Explanation:
Assigning `x = 5` inside `func()` creates a local variable `x`, leaving the global `x` unchanged at 10.
Correct Answer: b) UnboundLocalError
Explanation:
If a variable is assigned anywhere in a function, Python treats it as local throughout that function. Referencing it before assignment raises `UnboundLocalError`.
Correct Answer: b) A nested function that retains access to variables from its enclosing scope even after the outer function finishes execution
Explanation:
A closure occurs when a inner function references variables from its lexical environment, preserving them after the outer function returns.
Correct Answer: b) A function that takes another function as an argument and extends its behavior without modifying it directly
Explanation:
Decorators allow wrapping callable objects to modify or enhance their behavior dynamically.
Correct Answer: b) @
Explanation:
Placing `@decorator_name` above a function definition decorates that function.
Correct Answer: a) @functools.wraps
Explanation:
`functools.wraps` is a decorator applied to the wrapper function inside a custom decorator to copy the original function's attributes.
Correct Answer: a) 8
Explanation:
Parameter `a` receives `4`, and `b` defaults to `2`. The function computes `4 * 2 = 8`.
Correct Answer: b) [1] then [1, 2]
Explanation:
Default parameter values are evaluated once when the function is defined, so mutable defaults like lists persist across calls.
Correct Answer: b) Set default value to None and instantiate inside function body
Explanation:
Using `None` as a sentinel default value prevents unexpected side-effects caused by shared mutable instances.
Correct Answer: a) 10
Explanation:
`*args` collects `(1, 2, 3, 4)` into a tuple. `sum(args)` evaluates to `10`.
Correct Answer: b) 100
Explanation:
Since key 'x' is not present in `kwargs`, `.get('x', 100)` falls back to returning default value `100`.
Correct Answer: a) Parameters before `/` must be positional-only
Explanation:
In Python 3.8+, parameters before `/` are positional-only and cannot be passed using keyword argument syntax.
Correct Answer: b) Parameters following `*` must be keyword-only
Explanation:
A bare `*` indicates that all following parameters can only be supplied as keyword arguments.
Correct Answer: b) TypeError: b is positional-only
Explanation:
`b` appears before `/`, making it positional-only. Passing `b=2` as a keyword argument causes a `TypeError`.
Correct Answer: b) By comma-separating values in the return statement (returns a tuple)
Explanation:
Executing `return a, b` packs values into a tuple object returned to the caller.
Correct Answer: a) 14 6
Explanation:
`calculate` returns tuple `(14, 6)`, unpacked into `x = 14` and `y = 6`.
Correct Answer: b) World
Explanation:
The `nonlocal` keyword allows `inner()` to rebind `msg` in `outer()`'s scope to 'World'.
Correct Answer: b) locals()
Explanation:
`locals()` returns a dictionary containing current local namespace bindings.
Correct Answer: b) map()
Explanation:
`map(func, iterable)` yields an iterator that transforms elements by applying `func` to each.
Correct Answer: b) functools
Explanation:
In Python 3, `reduce()` was moved from built-in scope to the `functools` standard module.
Correct Answer: b) [1, 4, 9]
Explanation:
The lambda squares each element in `[1, 2, 3]`, resulting in `[1, 4, 9]`.
Correct Answer: b) [3, 4]
Explanation:
`filter()` retains items where the predicate lambda evaluates to `True` (`x > 2`).
Correct Answer: b) Higher-order functions
Explanation:
Higher-order functions operate on other functions by receiving them as arguments or returning them.
Correct Answer: b) Functions can be passed as arguments, assigned to variables, and returned from other functions
Explanation:
First-class status means functions are treated like any other object value in Python.
Correct Answer: a) 12
Explanation:
Assigning `f = double` creates a reference alias to `double`. Calling `f(6)` yields `12`.
Correct Answer: b) A function that produces deterministic outputs for identical inputs with no observable side-effects
Explanation:
Pure functions depend exclusively on input arguments and do not mutate global state.
Correct Answer: a) partial
Explanation:
`functools.partial(func, *args, **keywords)` returns a new callable object with fixed arguments.
Correct Answer: b) 25
Explanation:
`square` fixes `exponent=2`. Calling `square(5)` sets `base=5`, computing `5 ** 2 = 25`.
Correct Answer: a) 42
Explanation:
`a=2`, `b` uses default `10`, `c` is passed as `30`. Sum: `2 + 10 + 30 = 42`.
Correct Answer: b) Unpacks dictionary keys as keyword arguments `a=3, b=4`, returning 12
Explanation:
The `**` operator unpacks dictionary key-value pairs into matching keyword parameters.
Correct Answer: a) 4
Explanation:
The `*` operator unpacks sequence tuple `(8, 2)` into positional arguments `x=8` and `y=2`, computing `8 // 2 = 4`.
Correct Answer: b) yield
Explanation:
Presence of the `yield` statement inside a function turns it into a generator function.
Correct Answer: b) Pauses execution, saves state, and returns value to caller
Explanation:
`yield` suspends generator state and emits a value, allowing resumption on the next `next()` call.
Correct Answer: b) StopIteration
Explanation:
When a generator function completes execution without yielding further, Python raises `StopIteration`.
Correct Answer: b) 10 20
Explanation:
The first `next(g)` yields `10`; the second `next(g)` resumes and yields `20`.
Correct Answer: a) async def
Explanation:
Coroutines are defined using `async def` syntax.
Correct Answer: b) await
Explanation:
The `await` keyword suspends execution of an `async def` coroutine until the target complete.
Correct Answer: a) 2 3
Explanation:
`inner()` updates global `x` to 3. `outer()`'s local `x` stays 2. Thus `outer()` returns 2 and global `x` prints 3.
Correct Answer: b) Function annotations
Explanation:
Function annotations provide type hint syntax, e.g., `def add(a: int) -> int:`.
Correct Answer: b) func.__annotations__
Explanation:
Type annotations are accessible via the `__annotations__` dictionary attribute.
Correct Answer: b) No, annotations are ignored at runtime and used by static type analyzers
Explanation:
Python does not automatically enforce type annotations at runtime; they serve as metadata for analyzers like mypy.
Correct Answer: b) Returns 'Python'
Explanation:
Because annotations are unenforced metadata at runtime, string concatenation occurs normally.
Correct Answer: a) 15
Explanation:
`make_adder(5)` creates a closure with `n=5`. Calling `add_five(10)` returns `10 + 5 = 15`.
Correct Answer: a) Memoization
Explanation:
Memoization optimizes execution speed by storing computed call results indexed by input arguments.
Correct Answer: a) @functools.lru_cache
Explanation:
`functools.lru_cache` wraps functions with a Least Recently Used lookup cache.
Correct Answer: a) Optimization where recursive calls in tail position reuse current stack frames
Explanation:
TCO prevents stack frame growth when recursive calls form the final execution action in a function.
Correct Answer: b) No, CPython intentionally omits TCO to preserve full stack traces
Explanation:
CPython does not implement TCO, prioritizing accurate stack frame debugging information.
Correct Answer: b) [1, 1] [1, 1]
Explanation:
`f()` shares a single default list instance. Both calls mutate this instance, and both printed values reference the same updated list (`[1, 1]`).
Correct Answer: a) 10 20
Explanation:
`*t` unpacks tuple values into positional arguments `a = 10` and `b = 20`.
Correct Answer: b) 2 2 2
Explanation:
Lambdas bind to variable `i` lazily. When called after the loop finishes, `i` evaluates to 2 for all stored lambdas.
Correct Answer: a) Use default parameter arguments: `lambda i=i: i`
Explanation:
Setting default arguments `i=i` binds current loop value immediately during iteration.
Correct Answer: b) 0 1 2
Explanation:
Default argument evaluation binds values at function creation time, capturing 0, 1, and 2.
Correct Answer: a) On the `value` attribute of the raised `StopIteration` exception
Explanation:
When a generator returns a value, Python attaches that object to `StopIteration.value`.
Correct Answer: a) Delegates generation iteration to a subgenerator or iterable
Explanation:
`yield from ` delegates iteration directly to another generator or iterable sequence.
Correct Answer: a) [1, 2, 3]
Explanation:
`yield from sub()` exhausts yields 1 and 2, followed by `yield 3`, giving `[1, 2, 3]`.
Correct Answer: b) HELLO
Explanation:
The decorator replaces `greet` with `wrapper`, which transforms the return value to uppercase.
Correct Answer: b) It changes to the wrapper function's name ('wrapper')
Explanation:
Without `@wraps`, the original function attributes are shadowed by the inner wrapper function.
Correct Answer: a) super()
Explanation:
`super()` returns a proxy object delegating method calls to parent/sibling classes in MRO.
Correct Answer: a) func.__code__
Explanation:
The executable compiled code object of a function is stored in its `__code__` attribute.
Correct Answer: a) func.__code__.co_varnames
Explanation:
`co_varnames` is a tuple containing local variable names starting with function parameters.
Correct Answer: a) func.__closure__
Explanation:
If a function is a closure, `__closure__` contains cell objects holding bound free variables.
Correct Answer: a) 5
Explanation:
`cell_contents` retrieves the bound object (`5`) enclosed inside the cell.
Correct Answer: a) inspect
Explanation:
The `inspect` module provides functions like `inspect.signature()` to introspect parameters and callables.
Correct Answer: a) A Signature object mapping parameters and return annotations
Explanation:
`inspect.signature()` extracts structured parameter and return annotation metadata.
Correct Answer: a) 3
Explanation:
The `parameters` mapping tracks 'a', 'b', and 'args', giving a length of 3.
Correct Answer: b) Raises SyntaxError: positional argument follows keyword argument
Explanation:
Syntax rules require positional arguments to precede keyword arguments during invocation.
Correct Answer: a) SyntaxError
Explanation:
Positional argument `2` appears after keyword argument `a=1`, causing a `SyntaxError`.
Correct Answer: a) 0
Explanation:
`*numbers` receives an empty tuple `()`. `sum(())` evaluates to `0`.
Correct Answer: a) def f(*args, **kwargs): pass
Explanation:
Combining `*args` and `**kwargs` allows capturing any positional and keyword parameters.
Correct Answer: b) TypeError
Explanation:
Signature defines `c`, but keyword argument passes `z=5`, raising a `TypeError: got an unexpected keyword argument 'z'`.
Correct Answer: b) Parameter shadows the global variable within function scope
Explanation:
Local parameters shadow outer variables of the same identifier name inside function scope.
Correct Answer: b) 5
Explanation:
Assigning to local parameter `x` alters local scope only, leaving global `x` set to `5`.
Correct Answer: a) id()
Explanation:
`id()` returns the unique memory address identity of an object.
Correct Answer: a)
Explanation:
User-defined functions belong to instance type ``.
Correct Answer: b) Restricted to evaluating a single expression
Explanation:
Lambda function bodies are limited to a single expression that evaluates to a return value.
Correct Answer: a) Yes
Explanation:
A parameterless lambda evaluates and returns string literal `'Yes'` when invoked.
Correct Answer: a) None
Explanation:
`dict.get()` returns `None` by default when the target key is missing.
Correct Answer: a) 4.0
Explanation:
Keyword arguments map explicit parameter names regardless of order: `a=8, b=2`, computing `8 / 2 = 4.0`.
Correct Answer: a) func.__defaults__
Explanation:
Positional default argument values are saved as a tuple in `__defaults__`.
Correct Answer: a) func.__kwdefaults__
Explanation:
`__kwdefaults__` stores a dictionary of default values for keyword-only parameters.
Correct Answer: a) {'a': 1, 'b': 2}
Explanation:
`__kwdefaults__` returns a dictionary mapping keyword-only parameter names to default values.
Correct Answer: a) TypeError
Explanation:
Failing to supply a non-default keyword-only parameter raises a `TypeError`.
Correct Answer: a) 10
Explanation:
`a=1`, `b=(2, 3)`, `c=4`. Sum: `1 + (2 + 3) + 4 = 10`.
Correct Answer: a) Yes, using the `**` operator in function calls
Explanation:
Passing `func(**my_dict)` maps dictionary keys directly to matching keyword arguments.
Correct Answer: a) [1, 2, 'a']
Explanation:
Passing `None` as predicate to `filter()` removes falsey items, keeping truthy items (`[1, 2, 'a']`).
Correct Answer: a) Method chaining
Explanation:
Method chaining relies on methods returning object references (`return self`) to allow consecutive calls.
Correct Answer: a) done
Explanation:
The value returned from a generator is stored on the `value` attribute of the raised `StopIteration` exception.
Correct Answer: a) 10
Explanation:
`apply` receives reference to `double` and invokes `double(5)`, returning `10`.
Correct Answer: a) The decorated function name gets bound to None
Explanation:
Decorators replace decorated functions with their return value. If no return statement is executed, `None` is returned.
Correct Answer: a) None
Explanation:
`my_dec` returns `None`. Thus, variable binding for `add` becomes `None`.
Correct Answer: a) By adding an extra enclosing function layer that takes parameters and returns a decorator
Explanation:
A decorator factory uses three nested function levels: factory(args) -> decorator(func) -> wrapper(*args).
Correct Answer: a) Executes target 3 times
Explanation:
A decorator factory parameterizes wrapper execution loops, repeating function invocation.
Correct Answer: a) Function parameters are local to function scope
Explanation:
Parameters act as local variables initialized upon function call and discarded upon return.
Correct Answer: a) 1 a
Explanation:
Python dynamically handles passing different object types as function parameters.
Correct Answer: a) TypeError: got multiple values for argument 'a'
Explanation:
Passing both a positional argument and keyword argument for the same parameter name causes a `TypeError`.
Correct Answer: a) 16
Explanation:
`a=2`, default `b=2`, passed `c=4`. Product: `2 * 2 * 4 = 16`.
Correct Answer: a) *
Explanation:
The single asterisk `*` operator unpacks iterables into positional arguments.
Correct Answer: a) **
Explanation:
The double asterisk `**` operator unpacks dictionaries into keyword arguments.
Correct Answer: a)
Explanation:
Multiple comma-separated values in a return statement are automatically packed into a tuple.
Correct Answer: a) Invokes function execution
Explanation:
Parentheses `()` execute the callable object.
Correct Answer: a) Evaluates to the function object reference without calling it
Explanation:
Omitting parentheses accesses the function object directly.
Correct Answer: a) Hi
Explanation:
`a` stores a reference alias to `greet`. Invoking `a()` executes `greet()`, returning 'Hi'.
Correct Answer: a) 0
Explanation:
The `sum()` function initializes the summation with `start=0` by default.
Correct Answer: a) 16
Explanation:
`start` is set to `10`. Sum: `10 + (1 + 2 + 3) = 16`.
Correct Answer: a) zero
Explanation:
The expression evaluates `x == 0` as `True`, returning string `'zero'`.
Correct Answer: a) Terminates execution upon encountering the first executable return statement
Explanation:
Executing a return statement immediately terminates function execution and exits to the caller.
Correct Answer: a) 1
Explanation:
The function returns `1` immediately, ignoring the unreachable `return 2` statement.
Correct Answer: a) Yes, known as inner or nested functions
Explanation:
Python supports nested function declarations within outer function scopes.
Correct Answer: a) Inner
Explanation:
`outer()` invokes nested function `inner()`, returning string `'Inner'`.
Correct Answer: a) Raises NameError: name 'inner' is not defined
Explanation:
`inner` is scoped locally to `outer()` and invisible to global scope.
Correct Answer: a) Call stack
Explanation:
The call stack manages active execution frames representing nested function invocations.
Correct Answer: a) inspect.stack()
Explanation:
`inspect.stack()` returns a list of frame records for the caller's stack.
Correct Answer: a) 3
Explanation:
`co_argcount` tracks total positional parameters (including default parameters).
Correct Answer: a) No, variable argument collectors are not included in `co_argcount`
Explanation:
Variable argument parameters (`*args`, `**kwargs`) are stored separately in code object flags.
Correct Answer: a) 0
Explanation:
The function has 0 positional parameters; `*args` does not increment `co_argcount`.
Correct Answer: a) __get__
Explanation:
Functions implement the descriptor protocol via `__get__` to return bound method objects.
Correct Answer: a) A bound method automatically passes instance object as first argument `self`
Explanation:
Bound methods bind an instance reference (`self`) automatically as the first parameter.
Correct Answer: a)
Explanation:
Accessing a method via an instance returns a bound `` object.
Correct Answer: a)
Explanation:
Accessing a method directly through the class `A.m` yields an unbound standard ``.
Correct Answer: a) @classmethod
Explanation:
`@classmethod` transforms a method into a class method receiving `cls` as its first parameter.
Correct Answer: a) @staticmethod
Explanation:
`@staticmethod` prevents descriptor binding behavior, behaving like a standard function residing inside a class namespace.
Correct Answer: a) 7
Explanation:
Invoking the static method passes `a=3` and `b=4`, returning `7`.
Correct Answer: a) To define getter methods that can be accessed like attributes
Explanation:
`@property` enables attribute-access syntax (`obj.attr`) that transparently calls underlying getter functions.
Correct Answer: a) 42
Explanation:
Accessing property `c.x` invokes the underlying getter method, returning `42`.
Correct Answer: a) AttributeError: can't set attribute
Explanation:
Attempting to assign a value to a property lacking a setter method raises an `AttributeError`.
Correct Answer: a) pass
Explanation:
`pass` serves as a syntactically valid null operation placeholder.
Correct Answer: a) Yes, `...` is syntactically valid in function bodies
Explanation:
The `...` (Ellipsis) literal is a valid statement placeholder in function bodies.
Correct Answer: a) None
Explanation:
A function with body `...` executes to completion without return, implicitly returning `None`.
Correct Answer: a) Sample
Explanation:
The docstring string literal is stored in and retrieved from the `__doc__` attribute.
Correct Answer: a) True
Explanation:
Built-in `print` is a callable function object, so `callable(print)` returns `True`.
Correct Answer: a) callable()
Explanation:
`callable(obj)` returns `True` if the argument object implements a `__call__()` method.
Correct Answer: a) __call__()
Explanation:
Defining `__call__()` on a class makes its instances callable using parentheses.
Correct Answer: a) 15
Explanation:
Calling `add5(10)` triggers `__call__(10)`, returning `5 + 10 = 15`.
Correct Answer: a) Partial function application
Explanation:
Partial application binds argument values to produce a callable with fewer remaining parameters.
Correct Answer: a) Translating evaluation of a function with multiple arguments into a sequence of functions taking single arguments
Explanation:
Currying transforms `f(a, b, c)` into a chain of single-argument calls `f(a)(b)(c)`.
Correct Answer: a) 7
Explanation:
`curried_add(3)` returns a lambda with `a=3`. Invoking it with `(4)` computes `3 + 4 = 7`.
Correct Answer: a) The second function overwrites the first definition
Explanation:
Function definitions bind names to objects; defining a duplicate identifier rebinds the variable to the new function.
Correct Answer: a) second
Explanation:
The second definition rebinds name `f`, so `f()` returns `'second'`.
Correct Answer: a) No, subsequent function definitions overwrite earlier ones with the same name
Explanation:
Python does not support traditional compile-time function overloading out of the box.
Correct Answer: a) @functools.singledispatch
Explanation:
`@singledispatch` transforms a function into a generic function with single-dispatch type implementations.
Correct Answer: a) To supply type checker hints for multiple call signatures without providing runtime implementations
Explanation:
`@typing.overload` provides stub definitions for static analyzers like mypy.
Correct Answer: a) Pass-by-assignment (Pass-by-object-reference)
Explanation:
Python passes object references by value. Modifying mutable arguments affects caller state, whereas reassigning local names does not.
Correct Answer: a) [1, 2, 42]
Explanation:
Mutating a passed mutable list (`lst.append(42)`) modifies the referenced object in caller scope.
Correct Answer: a) [1, 2]
Explanation:
Rebinding local reference parameter `lst` does not affect caller variable `nums`.
Correct Answer: a) 5
Explanation:
Integers are immutable. `x += 10` rebinds local parameter `x`, leaving caller variable `val` set to `5`.
Correct Answer: a) help()
Explanation:
`help(func)` formats and outputs documentation string, signature, and module context.
Correct Answer: a) 15
Explanation:
`x` gets positional argument `5`, `y` takes positional default `10`. Result = `15`.
Correct Answer: a) Allows refactoring parameter names without breaking caller keyword code
Explanation:
Positional-only parameters decouple API parameter naming from public caller keyword syntax contracts.
Correct Answer: a) Yes, function definitions execute at runtime
Explanation:
In Python, `def` is an executable statement defining functions at runtime when executed.
Correct Answer: a) func.__module__
Explanation:
`__module__` stores the string name of the module containing the function definition.
Correct Answer: a) '__main__'
Explanation:
Top-level main scripts assign string `'__main__'` to `__module__`.
Correct Answer: a) ''
Explanation:
Anonymous lambda functions assign string `''` to `__name__`.
Correct Answer: a) func.__qualname__
Explanation:
`__qualname__` holds the qualified dotted path string leading to the function.
Correct Answer: a) vars()
Explanation:
`vars(obj)` returns the `__dict__` attribute dictionary of an object.
Correct Answer: a) Yes, function objects have a `__dict__` attribute allowing dynamic property assignment
Explanation:
Python functions support custom user properties stored in their `__dict__` dictionary.
Correct Answer: a) 1.0
Explanation:
Dynamic attribute `version` assigns value `'1.0'` directly to `f.__dict__`.
Correct Answer: a) 10
Explanation:
`reduce` applies cumulative addition: `((1 + 2) + 3) + 4 = 10`.
Correct Answer: a) 60
Explanation:
With initializer `10`: `((10 * 1) * 2) * 3 = 60`.
Correct Answer: a) TypeError
Explanation:
Reducing an empty iterable without providing an initial value raises a `TypeError`.
Correct Answer: a) True
Explanation:
Map evaluates element testing to `[True, True, True]`. Built-in `all()` returns `True`.
Correct Answer: a) Callable[[int, str], bool]
Explanation:
`Callable[[ParamTypes], ReturnType]` defines function type hints.
Correct Answer: a) NoReturn
Explanation:
`typing.NoReturn` annotates functions that terminate execution or unconditionally raise exceptions.
Correct Answer: a) 10
Explanation:
`make_mult(5)` creates closure with `n=5`. Calling `add_five(2)` computes `2 * 5 = 10`.
Related Posts
New
New
New

Python OOP MCQs
Object-Oriented Programming (OOP) in Python is a programming paradigm that uses classes and objects to model real world entities, promoting…
August 27, 2026By MCQs Generator

Python Strings MCQs
In Python, a string (str) is an immutable sequence of Unicode characters used to represent text data. Defined using single,…
August 27, 2026By MCQs Generator

Python Variables & Data Types MCQs
Variables in Python act as dynamic references reserved in memory to store objects, operating without explicit data type declarations due…
August 27, 2026By MCQs Generator
Related Categories
New












AI & Data Science MCQ
5 topics
By MCQs Generator
New
Arts & Humanities MCQ
4 topics
By MCQs Generator
New
Civil Engineering MCQ
4 topics
By MCQs Generator
New
Commerce & Business MCQ
4 topics
By MCQs Generator
New
Competitive Exams MCQ
5 topics
By MCQs Generator
New
Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator
New
General Knowledge MCQ
2 topics
By MCQs Generator
New
General Science MCQ
4 topics
By MCQs Generator
New
Law & Judiciary MCQ
3 topics
By MCQs Generator
New
Mechanical Engineering MCQ
4 topics
By MCQs Generator
New
Medical & Health Sciences MCQ
4 topics
By MCQs Generator
New
Modern Tech Fields MCQ
3 topics
By MCQs Generator