[Tutor] designing a class
Runsun Pan
python.pan at gmail.com
Fri Jan 27 07:59:48 CET 2006
On 1/26/06, Christopher Spears <cspears2002 at yahoo.com> wrote:
> headlights. Where should I begin? How do I go about
> designing a new class?
Some starter 101:
First, recognize that a class is a compound type that is not only a type
but binds other variables and methods with it.
#----------------------------------- class definition
class People(object):
lastname = 'Spears'
firstname = Chris
object is the parent of People from where People inherits all of its
definitions and behavior (functions). It's also called "subclassing" --
subclassing object to get People.
#----------------------------------- instantiation
p = People( )
p is called "an instance of class People"
>>> p.lastname
Spears
>>> p.firstname
Chris
>>> p.firstname = 'runsun'
>>> p.firstname
runsun
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
python.pan at gmail.com
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
More information about the Tutor
mailing list