On 24 Mar 2005 10:29:40 -0800, vahmad70@yahoo. com <vahmad70@yahoo .com> wrote:[color=blue]
> I am new to python and learning it. Can you please give me a simple
> example of user defined type through class mechanism.[/color]
vahmad70@yahoo. com wrote:
[color=blue]
> I am new to python and learning it. Can you please give me a simple
> example of user defined type through class mechanism.[/color]
Python 2.4 (#1, Dec 31 2004, 17:21:43)
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> class Gumby(object):[/color][/color][/color]
.... def __init__(self, body_part):
.... self.body_part = body_part
.... def speak(self):
.... print "My %s hurts!" % self.body_part
....[color=blue][color=green][color=darkred]
>>> g = Gumby("brain")
>>> g[/color][/color][/color]
<__main__.Gum by object at 0x402c570c>[color=blue][color=green][color=darkred]
>>> g.speak()[/color][/color][/color]
My brain hurts!
Despite what Mr Gumby just said, defining your own classes is pretty
painless in Python. Check out the Tutorial, especially section 9:
Comment