In python, the dot notation is used to access methods and/or variables defined in the class. An example is shown below.
This is where the functionality of classes and their ability to store values can be seen.
Methods use the dot notation as well: Just like a normal function, use parenthesis to call the method of myDuck
To create this function, add a few spaces between the first and second lines of the class and type def init(self): on the second line (make sure to indent). In the Duck example (self explained below):
The self word is the instance of the Duck class that is being created. This word can be whatever the programmer wishes as long as it is the first argument of the init function.
There is a much better way to do the same process - in one line. This will require a little manipulation of the Duck class:
Output:
Output:
Output: