INNER CODE UNIT · Python

__len__

webartifex/intro-to-python · 11_classes/sample_package/matrix.py:112

    def __len__(self):
        """Number of entries in a Matrix."""
        return self.n_rows * self.n_cols

    def __getitem__(self, index):
        """Obtain an individual entry of a Matrix.

        Args:
            index (int / tuple of int's): if index is an integer,
                the Matrix is viewed as a sequence in row-major order;
                if index is a tuple of integers, the first one refers to
                the row and the second one to the column of the entry

        Returns:
            entry (Matrix.typing)

        Example Usage:
            >>> m = Matrix([(1, 2), (3, 4)])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…