[Tutor] constructor

Emile van Sebille emile at fenx.com
Sun Apr 4 20:37:36 CEST 2010

On 4/4/2010 11:11 AM Shurui Liu (Aaron Liu) said...
> Sorry, let me specify. I think comptuter will print out those two
> sentences like this:

It's a little more interesting as you move forward from here.  This is a 
small step...

class Critter(object):
     """A virtual pet"""
     def __init__(self,name):
         print "A new critter has been born!"
         self.name = name
     def talk(self):
         print "\nHi.  I'm %s, an instance of class Critter." % self.name

# main
crit1 = Critter('Polly')
crit2 = Critter('Spot')




More information about the Tutor mailing list