Python:Ellipsis
lastmod 2021-04-18created 2021-04-181 edits
Python provides the ... operator for slicing, represented by a type called Ellipsis.
Slicing operator
Python provides a little-known slicing operator called ellipsis.
>>> class C(object):
... def __getitem__(self, item):
... return item
...
>>> C()[1:2, ..., 3]
(slice(1, 2, None), Ellipsis, 3)
When you write a class that slices directly through the square bracket [ ] operation, you can also use the dot-dot-dot syntax. It is mainly used in Numpy:
Arbitrary-type argument
class flow:
# (using "value: Any" to allow arbitrary types)
def __understand__(self, name: str, value: ...) -> None: ...