Objects

Lesson

Objects and Classes

  • Classes define objects using attributes and methods (functions)
  • Class: what we write
    • Be very cautious with the syntax used to create a class! Check out the syntax below as well as the examples in the playground.
  • Object: a single instance of that class
    • An instance is a single occurrence. So if you have two separate Heart objects, that is two separate instances of the Heart class!

How to write a class

  • Line 1: class {ClassName}:
    • {ClassName} is the name of your class. Normally these names are capitalized.
  • Line 2: def __init__ ({vars}):
    • {vars} are the variables for this function. This is anything you need in order to set up the class.
  • self.{variableName}: the objects own attribute

Playground