Python for Absolute Beginners

Lesson 5 of 6

Classes and Objects

A class is a blueprint for creating objects that bundle data and behavior together.

Pythonshares state with other Python blocks

Key pieces

  • __init__ is the constructor, it runs automatically whenever you create a new instance with Student(...).
  • self refers to the specific instance a method was called on, it's always the first parameter of an instance method.
  • Each instance (ada, grace) keeps its own independent copy of the data set in __init__.

📝 Classes Quiz

Passing score: 70%
  1. 1.The constructor method that runs automatically when a new instance is created is called ____.

  2. 2.What does `self` refer to inside an instance method?

  3. 3.Two instances of the same class always share the same attribute values.