Classes and Pointers
Classes
The following code creates a Cookie
class.
__init__
is a special method that is called when a new instance of a class is created. It is used to initialize the instance. __init__
is a constructor.
Pointers
The following piece of code is an example of not using a pointer.
In this case, updating num1
does not change num2
.
The following is an example of using a pointer.
In this case, updating dict1
changes dict2
. The reason is that dict1
and dict2
are pointing to the same object. The unused object will be garbage collected.
Last updated