.. index:: py::builtins::range::operator [] .. _doxycast_pypp_classpy_1_1builtins_1_1range_1a5f247e203331077e177534a81b398e7d: .. _py-builtins-range-operator-subscript: *py::builtins::range::*\ operator [] ==================================== .. code-block:: cpp constexpr type operator [] (long index) const; // 1 range operator [] (std::string properties) const; // 2 1. Returns the value at given index. 2. Returns a slice of the range with given start, stop and step. Parameters ---------- ``index``: The index of the element. ``properties``: The properties of slice. .. admonition:: Format of argument ``properties`` The value of ``properties`` must have the format:: "[start]:[stop][:step]" Return value ------------ 1. The value at given index. 2. A slice of the range with given start, stop and step. Complexity ---------- Constant. Example ------- .. code-block:: cpp #include #include int main() { py::range range(3); py::print(range[0]); py::print(range["1:2"]); // Slice } **Output**: .. code-block:: text 0 py::builtins::range<...>(1, 2)