June 2002
Beginner to intermediate
640 pages
14h 24m
English
In Python you can define special methods for classes that have special meaning. You can also define methods to make your class look like other objects such as lists, dictionaries, and tuples.
Like other OOP languages, Python has a destructor and a constructor. A constructor is called when an instance is instantiated. A destructor is called when an instance is garbage-collected. The method __init__ denotes the constructor. The method __del__ denotes the destructor.
Here's the Car class (Car2.py) with its constructor and destructor:
class Car: make = "?" model = "?" color = "?" running = 0 #1 is true, 0 is false def __init__(self, make, model, color): self.make = make self.model = model ...
Read now
Unlock full access