py::builtins::range::operator []

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.

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

#include <pypp/builtins/range.hpp>
#include <pypp/builtins/print.hpp>

int main()
{
    py::range<int> range(3);
    py::print(range[0]);
    py::print(range["1:2"]); // Slice
}

Output:

0
py::builtins::range<...>(1, 2)