[Tutor] How many types of the constructor

Emile van Sebille emile at fenx.com
Mon Apr 27 19:30:33 CEST 2009


sudhanshu gautam wrote:
<snip>

> Now If I placed the name of the constructor rather than the __init__
> __baba___ so will it also work as a constructor or constructor has 
> specified already if yes then give me list of them

I'm not sure I parsed your question as you intended, but __init__ is 
pretty much the constructor method ( with __new__ )

But I suspect you may be asking about that group know as magic methods, 
which you may want to look into.  These include things like __getattr__, 
__len__, __gt__, and lots more.  These make it easy to do things like:

 >>> class Test:
...     def __init__(self):pass
...     def __gt__(self,other): return True
...
 >>> t = Test()
 >>> t>3
True
 >>> t>0
True
 >>> t>"hello"
True
 >>>

And you may even find out why the following work as well...

 >>> t<"hello"
True
 >>> t <3
True
 >>>


Regards,

Emile



More information about the Tutor mailing list