PyAI Learn Türkçe

Module 10

Objects and classes

class, self, methods, operators

When you finish this module you can say:

I can write my own classes and teach them operators.

By the end of this module you'll be able to write a number class that can be added, multiplied, and prints itself readably. In Module 15 we'll add the ability to learn to this very same class.

Start

Lessons

8 lessons · ≈ 77 min

  1. Why a class?9 min
  2. class, __init__, and self10 min
  3. Methods9 min
  4. __repr__: printing an object readably8 min
  5. Inheritance and super()10 min
  6. Teaching operators to your own class10 min
  7. len, indexing, and looping9 min
  8. Project: the Value class12 min · project

Practice exercises

Short writing exercises, independent of the lessons: Go to the exercises

  1. A depot class
  2. How a tag looks
  3. Employee and manager
  4. A callable threshold
  5. A countdown object