[Tutor] __new__ over __init__

Payal payal-tutor at scriptkitchen.com
Wed Sep 1 03:45:22 CEST 2010


On Tue, Aug 31, 2010 at 08:27:10AM +0200, Peter Otten wrote:
> Subclasses of immutable types, e. g. tuple:

That was one great example, thanks. Some doubts,

a. I have seen this cls before, what does it mean?
b. What does type(_) mean?

Thanks a lot in advance.

With warm regards,
-Payal
-- 


> >>> class A(tuple):
> ...     def __new__(cls, a, b):
> ...             return tuple.__new__(cls, (a, b))
> ...
> >>> A(1, 2)
> (1, 2)
> >>> type(_)
> <class '__main__.A'>
> 
> Peter
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list