GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing docs.python.org — 7.6 Class definitions

Previous Page Up One Level Next Page Python Reference Manual Contents Index
Previous: 7.5 Function definitions Up: 7. Compound statements Next: 8. Top-level components


7.6 Class definitions

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

classdef:       "class" classname [inheritance] ":" suite
inheritance:    "(" [expression_list] ")"
classname:      identifier

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 ), 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 the __init__() method or in another method. Both class and instance variables are accessible through the notation ```codeself.name'', 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.


Previous Page Up One Level Next Page Python Reference Manual Contents Index
Previous: 7.5 Function definitions Up: 7. Compound statements Next: 8. Top-level components

See About this document... for information on suggesting changes.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.