Python%20Interview%20Questions%20and%20Answers
Question: How do you make a higher order function in Python?Answer:You have two choices: you can use nested scopes or you can use callable objects. For example,
Or using a callable object:
In both cases:
Object can encapsulate state for several methods: Here inc(), dec() and reset() act like functions which share the same counting variable. |
Most helpful rated by users:
- What is Python?
- How do I share global variables across modules?
- How do you set a global variable in a function in Python?
- Why can\'t I use an assignment in an expression?
- What are the rules for local and global variables in Python?