February 2006
Intermediate to advanced
648 pages
14h 53m
English
A class defines a set of attributes associated with a collection of objects known as instances. These attributes typically include functions, which are known as methods,variables, which are known as class variables, and computed attributes, which are known as properties.
Classes are defined using the class statement. The body of a class contains a series of statements that is executed when the class is first defined. Here’s an example:
class Account(object): "A simple class" num_accounts = 0 def __init__(self,name,balance): "Initialize a new Account instance" self.name = name self.balance = balance Account.num_accounts += 1 def __del__(self): Account.num_accounts -= 1 def deposit(self,amt): "Add to the balance" self.balance ...