py::builtins::range::operator []¶
constexpr type operator [] (long index) const; // 1
range operator [] (std::string properties) const; // 2
Returns the value at given index.
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¶
The value at given index.
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)