Skip to main content

Ellipsis

Properties​

>>> dir(...)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Definition​

The ellipsis literal, written as ..., is a built-in singleton object of type ellipsis.
It is commonly used as a placeholder to indicate omitted code, incomplete logic, or “this will be implemented later.”

def future_function():
...

class MyClass:
def method(self):
...

Using ellipsis​

Placeholder for incomplete code​

... is often used instead of pass when you want to clearly signal that something is intentionally left unfinished.

def future_function():
...

class MyClass:
def method(self):
...

In type hints​

Ellipsis can be used in type hints to indicate variadic arguments or incomplete type information:

from typing import Tuple

def process(*args: int) -> Tuple[int, ...]:
...

# In function signatures
def func(x: int, ...) -> None:
...

In slicing operations (NumPy and other libraries)​

Some libraries, particularly NumPy, interpret ... in slicing operations to mean "all remaining dimensions":

import numpy as np

arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
arr[..., 0] # Selects the first element along the last dimension

Singleton behavior​

Every occurrence of ... refers to the same singleton object:

>>> ... is Ellipsis
True

>>> ... is ...
True

>>> type(...)
<class 'ellipsis'>

>>> id(...) == id(Ellipsis)
True

Boolean value​

Ellipsis is truthy:

>>> bool(...)
True

>>> if ...:
... print("Ellipsis is truthy")
Ellipsis is truthy

Dunder methods​

Dunder MethodOperationExample (normal syntax)Example (dunder call)
__repr__Object representationrepr(...) → 'Ellipsis'....__repr__()
__str__String conversionstr(...) → 'Ellipsis'....__str__()
__bool__Truth valuebool(...) → True....__bool__()
__eq__Equality comparison... == Ellipsis → True....__eq__(Ellipsis)
__ne__Inequality comparison... != None → True....__ne__(None)
__hash__Hash valuehash(...)....__hash__()
__lt__Less than... < Ellipsis → False....__lt__(Ellipsis)
__le__Less than or equal... <= Ellipsis → True....__le__(Ellipsis)
__gt__Greater than... > Ellipsis → False....__gt__(Ellipsis)
__ge__Greater than or equal... >= Ellipsis → True....__ge__(Ellipsis)