Interactive tutorial

Classes and Objects in Object-Oriented Programming

Learn how classes define objects and how each object stores state and performs actions. Using short Python examples, you will create instances, initialize attributes, write methods, and distinguish separate objects from shared references. Finish by completing a small class and predicting how its objects behave.

  • Level: Beginner
  • Duration: approx. 30 min
  • 7 steps
Classes and Objects in Object-Oriented Programming

What you will go through

  1. Step 1 of 7 3 min A Class Defines; an Object Exists Distinguish a class from its instances and recognize the state and behavior that make up an object.
  2. Step 2 of 7 3 min Define a Class and Create Instances Define a minimal Python class and use separate class calls to create two distinct instances.
  3. Step 3 of 7 5 min Give Each Object Its Own State Initialize labeled Lamp instances and see how `self` stores separate state on each object.
  4. Step 4 of 7 5 min Add Behavior with Instance Methods Define instance methods, call them with dot notation, and trace how they change a Lamp object’s state.
  5. Step 5 of 7 4 min Separate Objects and Shared References Learn to distinguish separate Lamp instances from two variables that refer to one shared Lamp object.
  6. Step 6 of 7 3 min Turn Requirements into a Class Design Turn a short requirement into a focused class design by separating the entity, its per-instance state, its initial state, and its actions.
  7. Step 7 of 7 7 min Complete and Trace Your Own Class Complete a Fan class, trace two independent instances, and verify how object state changes over time.

Video Courses

Courses related to this topic

See all video courses

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate