Website hosting service by

 Back to Index

7.6 Class definitions

A class definition defines a class object (see section 3.2):


classdef  ::=  "class" classname [inheritance] ":" suite
inheritance  ::=  "(" [expression_list] ")"
classname  ::=  identifier
Download entire grammar as text.

A class definition is an executable statement. It first evaluates the inheritance list, if present. Each item in the inheritance list should evaluate to a class object. The class's suite is then executed in a new execution frame (see section 4.1), using a newly created local namespace and the original global namespace. (Usually, the suite contains only function definitions.) When the class's suite finishes execution, its execution frame is discarded but its local namespace is saved. A class object is then created using the inheritance list for the base classes and the saved local namespace for the attribute dictionary. The class name is bound to this class object in the original local namespace.

Programmer's note: variables defined in the class definition are class variables; they are shared by all instances. To define instance variables, they must be given a value in the __init__() method or in another method. Both class and instance variables are accessible through the notation ``'', and an instance variable hides a class variable with the same name when accessed in this way. Class variables with immutable values can be used as defaults for instance variables.




2002-2004 Website Hosting Service


Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to offers cheap domain registration, domain name transfer and domain search services   Cheap domain name - Cheap domain name registration service including free domain hosting services  

Domain registration : Buy domain name or register domain name from $5.95/year only