def next_basis_label_or_index(self, label_or_index, n=1):
        """Given the label or index of a basis state, return the label
        the next basis state.

        More generally, if `n` is given, return the `n`'th next basis state
        label/index; `n` may also be negative to obtain previous basis state
        labels. Returns a :class:`str` label if `label_or_index` is a
        :class:`str` or :class:`int`, or a :class:`SpinIndex` if
        `label_or_index` is a :class:`SpinIndex`.

        Args:
            label_or_index (int or str or SpinIndex): If `int`, the
                zero-based index of a basis state; if `str`, the label of a
                basis state
            n (int): The increment

        Raises:
            IndexError: If going beyond the last or first basis state
            ValueError: If `label` is not a label for any basis state in the
                Hilbert space
            .BasisNotSetError: If the Hilbert space has no defined basis
            TypeError: if `label_or_index` is neither a :class:`str` nor an
                :class:`int`, nor a :class:`SpinIndex`

        Note:
            This differs from its super-method only by never returning an
            integer index (which is not accepted when instantiating a
            :class:`BasisKet` for a :class:`SpinSpace`)
        """
        if isinstance(label_or_index, int):
            new_index = label_or_index + n
            if new_index < 0:
                raise IndexError("index %d < 0" % new_index)
            if new_index >= self.dimension:
                raise IndexError(
                    "index %d out of range for basis %s"
                    % (new_index, self._basis))
            return self.basis_labels[new_index]
        elif isinstance(label_or_index, str):
            label_index = self.basis_labels.index(label_or_index)
            new_index = label_index + n
            if (new_index < 0) or (new_index >= len(self._basis)):
                raise IndexError(
                    "index %d out of range for basis %s"
                    % (new_index, self._basis))
            return self.basis_labels[new_index]
        elif isinstance(label_or_index, SpinIndex):
            return label_or_index.__class__(expr=label_or_index.expr + n)
def next_basis_label_or_index ( self , label_or_index , n = 1 ) : if isinstance ( label_or_index , int ) : new_index = label_or_index + n if new_index < 0 : raise IndexError ( "index %d < 0" % new_index ) if new_index >= self . dimension : raise IndexError ( "index %d out of range for basis %s" % ( new_index , self . _basis ) ) return self . basis_labels [ new_index ] elif isinstance ( label_or_index , str ) : label_index = self . basis_labels . index ( label_or_index ) new_index = label_index + n if ( new_index < 0 ) or ( new_index >= len ( self . _basis ) ) : raise IndexError ( "index %d out of range for basis %s" % ( new_index , self . _basis ) ) return self . basis_labels [ new_index ] elif isinstance ( label_or_index , SpinIndex ) : return label_or_index . __class__ ( expr = label_or_index . expr + n )
Given the label or index of a basis state, return the label
        the next basis state.

        More generally, if `n` is given, return the `n`'th next basis state
        label/index; `n` may also be negative to obtain previous basis state
        labels. Returns a :class:`str` label if `label_or_index` is a
        :class:`str` or :class:`int`, or a :class:`SpinIndex` if
        `label_or_index` is a :class:`SpinIndex`.

        Args:
            label_or_index (int or str or SpinIndex): If `int`, the
                zero-based index of a basis state; if `str`, the label of a
                basis state
            n (int): The increment

        Raises:
            IndexError: If going beyond the last or first basis state
            ValueError: If `label` is not a label for any basis state in the
                Hilbert space
            .BasisNotSetError: If the Hilbert space has no defined basis
            TypeError: if `label_or_index` is neither a :class:`str` nor an
                :class:`int`, nor a :class:`SpinIndex`

        Note:
            This differs from its super-method only by never returning an
            integer index (which is not accepted when instantiating a
            :class:`BasisKet` for a :class:`SpinSpace`)