@@ -585,6 +585,7 @@ \section{Special method names} \label{specialnames}
585585class, then \verb @x[i] @ is equivalent to \verb @x.__getitem__(i) @.
586586(The reverse is not true --- if \verb @x @ is a list object,
587587\verb @x.__getitem__(i) @ is not equivalent to \verb @x[i] @.)
588+ \ttindex {__getitem__}
588589
589590Except for \verb @__repr__ @, \verb @__str__ @ and \verb @__cmp__ @,
590591attempts to execute an
@@ -594,6 +595,9 @@ \section{Special method names} \label{specialnames}
594595For \verb @__cmp__ @, the default is to compare instances based on their
595596address.
596597For \verb @__str__ @, the default is to use \verb @__repr__ @.
598+ \ttindex {__repr__}
599+ \ttindex {__str__}
600+ \ttindex {__cmp__}
597601
598602
599603\subsection {Special methods for any type }
@@ -606,6 +610,9 @@ \subsection{Special methods for any type}
606610\code {__init__} method the derived class's \code {__init__} method must
607611explicitly call it to ensure proper initialization of the base class
608612part of the instance.
613+ \ttindex {__init__}
614+ \indexii {class}{constructor}
615+
609616
610617\item [{\tt __del__(self)}]
611618Called when the instance is about to be destroyed. If a base class
@@ -617,6 +624,8 @@ \subsection{Special methods for any type}
617624reference is deleted. It is not guaranteed that
618625\code {__del__} methods are called for objects that still exist when
619626the interpreter exits.
627+ \ttindex {__del__}
628+ \stindex {del}
620629
621630Note that \code {del x} doesn't directly call \code {x.__del__} --- the
622631former decrements the reference count for \code {x} by one, but
@@ -625,6 +634,8 @@ \subsection{Special methods for any type}
625634\item [{\tt __repr__(self)}]
626635Called by the \verb @repr() @ built-in function and by string conversions
627636(reverse or backward quotes) to compute the string representation of an object.
637+ \ttindex {__repr__}
638+ \bifuncindex {repr}
628639\indexii {string}{conversion}
629640\indexii {reverse}{quotes}
630641\indexii {backward}{quotes}
@@ -633,6 +644,9 @@ \subsection{Special methods for any type}
633644\item [{\tt __str__(self)}]
634645Called by the \verb @str() @ built-in function and by the \verb @print @
635646statement compute the string representation of an object.
647+ \ttindex {__str__}
648+ \bifuncindex {str}
649+ \stindex {print}
636650
637651\item [{\tt __cmp__(self, other)}]
638652Called by all comparison operations. Should return -1 if
@@ -642,6 +656,9 @@ \subsection{Special methods for any type}
642656(Implementation note: due to limitations in the interpreter,
643657exceptions raised by comparisons are ignored, and the objects will be
644658considered equal in this case.)
659+ \ttindex {__cmp__}
660+ \bifuncindex {cmp}
661+ \index {comparisons}
645662
646663\item [{\tt __hash__(self)}]
647664Called for the key object for dictionary operations,
@@ -659,9 +676,14 @@ \subsection{Special methods for any type}
659676\code {__hash__}, since the dictionary implementation assumes that a
660677key's hash value is a constant.
661678\obindex {dictionary}
679+ \ttindex {__cmp__}
680+ \ttindex {__hash__}
681+ \bifuncindex {hash}
662682
663683\item [{\tt __call__(self, *args)}]
664684Called when the instance is `` called'' as a function.
685+ \ttindex {__call__}
686+ \indexii {call}{instance}
665687
666688\end {description }
667689
@@ -677,6 +699,7 @@ \subsection{Special methods for attribute access}
677699Called when an attribute lookup has not found the attribute in the
678700usual places (i.e. it is not an instance attribute nor is it found in
679701the class tree for \code {self}). \code {name} is the attribute name.
702+ \ttindex {__getattr__}
680703
681704Note that if the attribute is found through the normal mechanism,
682705\code {__getattr__} is not called. (This is an asymmetry between
@@ -687,22 +710,26 @@ \subsection{Special methods for attribute access}
687710Note that at least for instance variables, \code {__getattr__} can fake
688711total control by simply not inserting any values in the instance
689712attribute dictionary.
713+ \ttindex {__setattr__}
690714
691715\item [{\tt __setattr__(self, name, value)}]
692716Called when an attribute assignment is attempted. This is called
693717instead of the normal mechanism (i.e. store the value as an instance
694718attribute). \code {name} is the attribute name, \code {value} is the
695719value to be assigned to it.
720+ \ttindex {__setattr__}
696721
697722If \code {__setattr__} wants to assign to an instance attribute, it
698723should not simply execute \code {self.\var {name} = value} --- this would
699724cause a recursive call. Instead, it should insert the value in the
700725dictionary of instance attributes, e.g. \code {self.__dict__[name] =
701726value}.
727+ \ttindex {__dict__}
702728
703729\item [{\tt __delattr__(self, name)}]
704730Like \code {__setattr__} but for attribute deletion instead of
705731assignment.
732+ \ttindex {__delattr__}
706733
707734\end {description }
708735
@@ -716,19 +743,23 @@ \subsection{Special methods for sequence and mapping types}
716743the length of the object, an integer \verb @>= @ 0. Also, an object
717744whose \verb @__len__() @ method returns 0 is considered to be false in a
718745Boolean context.
746+ \ttindex {__len__}
719747
720748\item [{\tt __getitem__(self, key)}]
721749Called to implement evaluation of \verb @self[key] @. Note that the
722750special interpretation of negative keys (if the class wishes to
723751emulate a sequence type) is up to the \verb @__getitem__ @ method.
752+ \ttindex {__getitem__}
724753
725754\item [{\tt __setitem__(self, key, value)}]
726755Called to implement assignment to \verb @self[key] @. Same note as for
727756\verb @__getitem__ @.
757+ \ttindex {__setitem__}
728758
729759\item [{\tt __delitem__(self, key)}]
730760Called to implement deletion of \verb @self[key] @. Same note as for
731761\verb @__getitem__ @.
762+ \ttindex {__delitem__}
732763
733764\end {description }
734765
@@ -743,14 +774,17 @@ \subsection{Special methods for sequence types}
743774respectively, and \verb @len(self) @ has been added (once) to originally
744775negative \verb @i @ or \verb @j @ by the time this function is called
745776(unlike for \verb @__getitem__ @).
777+ \ttindex {__getslice__}
746778
747779\item [{\tt __setslice__(self, i, j, sequence)}]
748780Called to implement assignment to \verb @self[i:j] @. Same notes as for
749781\verb @__getslice__ @.
782+ \ttindex {__setslice__}
750783
751784\item [{\tt __delslice__(self, i, j)}]
752785Called to implement deletion of \verb @self[i:j] @. Same notes as for
753786\verb @__getslice__ @.
787+ \ttindex {__delslice__}
754788
755789\end {description }
756790
@@ -774,17 +808,34 @@ \subsection{Special methods for numeric types}
774808Called to implement the binary arithmetic operations (\verb @+ @,
775809\verb @- @, \verb @* @, \verb @/ @, \verb @% @, \verb @divmod() @, \verb @pow() @,
776810\verb @<< @, \verb @>> @, \verb @& @, \verb @^ @, \verb @| @).
811+ \ttindex {__or__}
812+ \ttindex {__xor__}
813+ \ttindex {__and__}
814+ \ttindex {__rshift__}
815+ \ttindex {__lshift__}
816+ \ttindex {__pow__}
817+ \ttindex {__divmod__}
818+ \ttindex {__mod__}
819+ \ttindex {__div__}
820+ \ttindex {__mul__}
821+ \ttindex {__sub__}
822+ \ttindex {__add__}
777823
778824\item [{\tt __neg__(self)}]\itemjoin
779825\item [{\tt __pos__(self)}]\itemjoin
780826\item [{\tt __abs__(self)}]\itemjoin
781827\item [{\tt __invert__(self)}]\itembreak
782828Called to implement the unary arithmetic operations (\verb @- @, \verb @+ @,
783829\verb @abs() @ and \verb @~ @).
830+ \ttindex {__invert__}
831+ \ttindex {__abs__}
832+ \ttindex {__pos__}
833+ \ttindex {__neg__}
784834
785835\item [{\tt __nonzero__(self)}]
786836Called to implement boolean testing; should return 0 or 1. An
787837alternative name for this method is \verb @__len__ @.
838+ \ttindex {__nonzero__}
788839
789840\item [{\tt __coerce__(self, other)}]
790841Called to implement `` mixed-mode'' numeric arithmetic. Should either
@@ -794,6 +845,7 @@ \subsection{Special methods for numeric types}
794845interpreter will also ask the other object to attempt a coercion (but
795846sometimes, if the implementation of the other type cannot be changed,
796847it is useful to do the conversion to the other type here).
848+ \ttindex {__coerce__}
797849
798850Note that this method is not called to coerce the arguments to \verb @+ @
799851and \verb @* @, because these are also used to implement sequence
@@ -803,16 +855,22 @@ \subsection{Special methods for numeric types}
803855\footnote {The interpreter should really distinguish between
804856user-defined classes implementing sequences, mappings or numbers, but
805857currently it doesn't --- hence this strange exception.}
858+ \ttindex {__mul__}
806859
807860\item [{\tt __int__(self)}]\itemjoin
808861\item [{\tt __long__(self)}]\itemjoin
809862\item [{\tt __float__(self)}]\itembreak
810863Called to implement the built-in functions \verb @int() @, \verb @long() @
811864and \verb @float() @. Should return a value of the appropriate type.
865+ \ttindex {__float__}
866+ \ttindex {__long__}
867+ \ttindex {__int__}
812868
813869\item [{\tt __oct__(self)}]\itemjoin
814870\item [{\tt __hex__(self)}]\itembreak
815871Called to implement the built-in functions \verb @oct() @ and
816872\verb @hex() @. Should return a string value.
873+ \ttindex {__hex__}
874+ \ttindex {__oct__}
817875
818876\end {description }
0 commit comments