Python
Ellipsis
Programming
Python Tips
Python Syntax

What does the Ellipsis object do?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

In Python, ... is not punctuation magic. It is a real built-in singleton object named Ellipsis. You can write it either as ... or as Ellipsis, and both names refer to the same object.

Most everyday Python code never needs it, which is why it feels mysterious. Its main practical uses are advanced slicing, placeholder bodies, and APIs that intentionally interpret Ellipsis as a special sentinel value.

Ellipsis is a real object

You can inspect it directly in normal Python code:

python
print(Ellipsis)
print(type(Ellipsis))
print(... is Ellipsis)

This prints something like:

python
Ellipsis
<class 'ellipsis'>
True

Because it is a singleton, identity checks are the right way to compare it:

python
1value = ...
2
3if value is Ellipsis:
4    print("Special marker detected")

That makes Ellipsis behave a bit like None in the sense that it can serve as a distinguished marker, but its meaning is entirely up to the surrounding code.

Use it in multidimensional slicing

The most common real-world use is in array libraries such as NumPy. Ellipsis means "fill in however many full slices are needed here."

python
1import numpy as np
2
3arr = np.arange(24).reshape(2, 3, 4)
4
5print(arr[1, ...].shape)     # (3, 4)
6print(arr[..., 0].shape)     # (2, 3)
7print(arr[0, ..., 2])        # [2 6 10]

Without ..., you would have to write all the intermediate colons explicitly. That becomes tedious as dimensionality grows.

For example, these two expressions are equivalent for a three-dimensional array:

python
arr[..., 0]
arr[:, :, 0]

The first form is easier to maintain when the number of middle dimensions is large or may change.

Use it as a placeholder deliberately

Python also allows ... as a valid expression, so developers sometimes use it as a placeholder in unfinished code:

python
def build_report(data):
    ...

This is legal Python. The function body runs and evaluates the Ellipsis object, then immediately returns None. That means it is a placeholder, not a blocker.

If you want unfinished code to fail loudly, raise an exception instead:

python
def build_report(data):
    raise NotImplementedError

That difference matters. ... is silent, while NotImplementedError makes the missing implementation obvious.

Use it as a custom sentinel

Sometimes None already has business meaning, and you need a different sentinel to mean "argument not provided". Ellipsis can serve that role:

python
1def update_profile(display_name=Ellipsis):
2    if display_name is Ellipsis:
3        print("No update requested")
4    elif display_name is None:
5        print("Clear the display name")
6    else:
7        print(f"Set display name to {display_name}")

This works because Ellipsis is unique and unlikely to appear accidentally in user data. That said, many teams prefer a dedicated private sentinel object because it communicates intent more clearly than reusing Ellipsis.

Common Pitfalls

  • Assuming ... automatically means "not implemented" when Python itself gives it no such behavior.
  • Using ... as a placeholder in a function body and forgetting that the function still executes and returns None.
  • Reusing Ellipsis as a custom sentinel when a dedicated private sentinel object would communicate intent more clearly.
  • Confusing the Ellipsis object with slicing syntax itself rather than the indexed object's interpretation of it.
  • Expecting ordinary Python lists or all custom classes to support ... in indexing the way NumPy does.

Summary

  • '... and Ellipsis refer to the same built-in singleton object.'
  • Its most common practical use is multidimensional slicing, especially in NumPy.
  • It can be used as a placeholder, but it does not automatically raise an error.
  • 'Ellipsis can act as a sentinel when None already has a separate meaning.'
  • Its behavior in indexing depends on the object being indexed, not on Python alone.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.