You are required to implement a Python function that needs to maintain its state between calls. Which Python feature would you use to achieve this?

  • Class
  • Closure
  • Decorator
  • Lambda

To maintain state between function calls in Python, you would use closures. A closure is a function object that remembers values in the enclosing scope even if they are not present in memory. Classes, decorators, and lambdas have other purposes and are not primarily designed for state maintenance.

Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *