Functions
don't keep the state from the last call.If you call them, the function itself has no information about the call before.
Special case of
functions
.Methods
are also functions
, but the instance of the class
can memorize
the state
.The
method
can access to the current state
.It's often the case, that you start with plain functions and later you recognize, that some of the used functions need access to variables in other functions. Then you refactor your code and put those functions in a class. Then you can share across the methods the needed variables (right term is: names, which refer to objects). This happens for example if you work with tkinter (integrated GUI Framework). Many examples do not use classes together with tkinter, but if the program get more complex, classes will help.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!