Skip to content
Snippets Groups Projects

Corrections - Tom

Merged Tom Reclik requested to merge tom into master
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
+ 2
2
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
**We notice:**
**We notice:**
* The class is defined by the keyword ```class```, followed by the name of the class
* The class is defined by the keyword ```class```, followed by the name of the class
* Each class needs to be initialised, this is done in the function defined with ```___init___()```. The function with a double underscore before and after the keyword is called a "dunder" or "magic" method in python. These methods are not intended to be called directly (by us), but they are typically called internally by some other method or action. In our case, this "magic" method is automatically called when we create an instance of this class. This initialisation function can take one or more optinal arguments. Typically, we define variables here that define the properties of our class.
* Each class needs to be initialised, this is done in the function defined with ```___init___()```. The function with a double underscore before and after the keyword is called a "dunder" or "magic" method in python. These methods are not intended to be called directly (by us), but they are typically called internally by some other method or action. In our case, this "magic" method is automatically called when we create an instance of this class. This initialisation function can take one or more optional arguments. Typically, we define variables here that define the properties of our class.
* The indicator ```self``` indicates the instance of this class. It is not a keyword as such (we could use some other word) - but pretty much everyone uses *self* to avoid confusion. We use this to refer to, e.g., the variables or functions that are part of this class.
* The indicator ```self``` indicates the instance of this class. It is not a keyword as such (we could use some other word) - but pretty much everyone uses *self* to avoid confusion. We use this to refer to, e.g., the variables or functions that are part of this class.
* A class can have one or more functions that define the functionality. They can (or not) have return values, they may operate on internal variables of the class, etc.
* A class can have one or more functions that define the functionality. They can (or not) have return values, they may operate on internal variables of the class, etc.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
> All variables in python are public.
> All variables in python are public.
All variables that are part of the class are public, i.e. we cannot prevent someone to access them directly an change them. For example:
All variables that are part of the class are public, i.e. we cannot prevent someone to access them directly and change them. For example:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
Loading