Classes
Reference:
A Class is a representation of one or more objects which share the same or similar properties. Each class is like its own custom data type with properties defined by the developer.
In Python, class definition requires a specific function called __init__()
to initialize, or create a new member of the object class.
Definition
To setup this example, create a new directory on your Desktop called class-time
or something. Inside it, create a new file called baseball_team.py
and place inside the following contents:
Initialization
After defining an object class, create a new member of that object class. This is called "instantiating", or "initializing", or creating an "instance" of the object class.
Normally we would reference the class from another file by importing it (e.g. from baseball_team import BaseballTeam
), but for example purposes, place the following contents at the bottom of the baseball_team.py
script:
Last updated