Mar 16, 2023
Functions are objects in Python, so as you say a function can have variables.
It can also have methods.
You can also create your own class that can be called like a function, by implementing the __call__ magic method. If you are wanting to do this sort of thing it is probably better to define a class to do it rather than adding members to a function. It is less confusing to anyone reading the code.