CIS 4930 PYTHON MIDTERM EXAM
2025/2026 QUESTIONS AND ANSWERS
100% PASS
What are the three characteristics of every object? - ANS Every object has
1) an identity
2) a type (its class)
3) a value
What is an object's identity? - ANS A number representing the object's physical location in
memory
What is an object's type? - ANS It's internal data representation and the methods it supports
What happens during a context manager's scope? - ANS If there are no exceptions being
handled, the exit function will receive None as the value of all three of its arguments.
If there are exceptions, the exit function should define what steps, if any, to take, including
automatic resource management (cleanup).
At the end of exit, return either
- True: any pending exception is cleared and the program continues execution normally with
the first statement after the with block
- False: preferrable; if an exception happened, it was not completely handled and should be
propagated up towards the interpreters at runtime
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
, What three protocols should you adhere to rigorously? - ANS 1) Create a proper object
representation using the __repr__() method
2) Iteration is a very big deal; make sure your code works with Python's for statement.
3) Use context managers and the with statement for resource management.
How do you define a function? - ANS - Use the def statement; i.e. def function_name()
How do you check for default variable values and None? - ANS - Default parameters are
evaluated once when the function is first defined, not each time the function is called.
- Use None as the default value for all arguments that should be mutable.
- As a rule, only use immutable objects for default argument values.
When can you mix positional and keyword arguments in a function call? - ANS 1) Positional
arguments appear first in the call.
2) Values are provided for all non-optional arguments.
3) No argument receives more than one value.
How do you define a function that accepts all arguments? - ANS def func(*args, **kwargs)
Can you redefine Python precedence evaluation? - ANS No
Write a function to perform math on an arbitrary number of arguments, including proper type
hinting and documentation. - ANS def addMany(first: int, *args) -> int:
if not isinstance(int, first):
raise TypeError("First value must be an integer")
total: int = first
for arg in args:
if isinstance(int, arg):
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
2025/2026 QUESTIONS AND ANSWERS
100% PASS
What are the three characteristics of every object? - ANS Every object has
1) an identity
2) a type (its class)
3) a value
What is an object's identity? - ANS A number representing the object's physical location in
memory
What is an object's type? - ANS It's internal data representation and the methods it supports
What happens during a context manager's scope? - ANS If there are no exceptions being
handled, the exit function will receive None as the value of all three of its arguments.
If there are exceptions, the exit function should define what steps, if any, to take, including
automatic resource management (cleanup).
At the end of exit, return either
- True: any pending exception is cleared and the program continues execution normally with
the first statement after the with block
- False: preferrable; if an exception happened, it was not completely handled and should be
propagated up towards the interpreters at runtime
1 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED
, What three protocols should you adhere to rigorously? - ANS 1) Create a proper object
representation using the __repr__() method
2) Iteration is a very big deal; make sure your code works with Python's for statement.
3) Use context managers and the with statement for resource management.
How do you define a function? - ANS - Use the def statement; i.e. def function_name()
How do you check for default variable values and None? - ANS - Default parameters are
evaluated once when the function is first defined, not each time the function is called.
- Use None as the default value for all arguments that should be mutable.
- As a rule, only use immutable objects for default argument values.
When can you mix positional and keyword arguments in a function call? - ANS 1) Positional
arguments appear first in the call.
2) Values are provided for all non-optional arguments.
3) No argument receives more than one value.
How do you define a function that accepts all arguments? - ANS def func(*args, **kwargs)
Can you redefine Python precedence evaluation? - ANS No
Write a function to perform math on an arbitrary number of arguments, including proper type
hinting and documentation. - ANS def addMany(first: int, *args) -> int:
if not isinstance(int, first):
raise TypeError("First value must be an integer")
total: int = first
for arg in args:
if isinstance(int, arg):
2 @COPYRIGHT 2025/2026 ALLRIGHTS RESERVED