Session Ready
Exercise

Changing class attributes

You learned how to define class attributes and how to access them from class instances. So what will happen if you try to assign another value to a class attribute when accessing it from an instance? The answer is not as simple as you might think!

The Player class from the previous exercise is pre-defined. Recall that it has a position instance attribute, and MAX_SPEED and MAX_POSITION class attributes. The initial value of MAX_SPEED is 3.

Instructions 1/2
undefined XP
  • 1
  • 2
  • Create two Player objects p1 and p2.
  • Print p1.MAX_SPEED and p2.MAX_SPEED.
  • Assign 7 to p1.MAX_SPEED.
  • Print p1.MAX_SPEED and p2.MAX_SPEED again.
  • Print Player.MAX_SPEED.
  • Examine the output carefully.