Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

The class Statement

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book