Python Reading
Key Ideas
- Thus far, we have used the procedural paradigm to
solve problems. With the procedural paradigm, the focus on solving
a problem is on the actions. In Python, these
actions are implemented with functions.
- Python also supports the object-oriented programming paradigm.
With the OOP paradigm, the focus on solving a problem is on the objects.
An object contains both data (called the state) and
functionality (called methods).
- Example: Consider the turtle module.
This module is implemented using object-oriented
programming. What are three methods that each turtle has?
What are three aspects of a turtle's state?
In-Class Activity
- Take a look at date.py.
- What are the state variables of the Date class?
- What are the methods of the Date class?
- Terminology: The __init__ method is called a constructor.
- Terminology: The getMonth, getDay and getYear methods are
called reader methods.
- Terminology: The setDay method is called a writer method.
- Terminology: Another name for a state variable is an
instance variable.
- Are there any aspects of date.py that you do not understand?
Active Learning
- Create a class named Pokemon that has the following
instance variables: number, name and combatPoints.
Add a constructor method that enables a new Pokémon to
be created. Add methods named getName, getNumber,
getCombatPoints and setCombatPoints. Write a program that
utilizes the functionality of the Pokémon class in its entirety.