Next / Previous / Contents / TCC Help System / NM Tech homepage

26.3.22. __setitem__(): Assign a value to one item of a sequence

If a class defines it, this method is called whenever a new value is stored into a sequence or mapping (dictionary-like object), such as in statements of this form:

V[i]  =  expr

Here is the calling sequence:

    def __setitem__(self, i, value):

For sequence-type objects, the i argument specifies the position in the sequence to be modified. For mappings, the i argument is the key under which the value is to be stored.