Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Python Land
  • Python Tutorial
  • Courses
  • Blog
  • Contact
  • Log in
Home » Blog » Python Ellipsis (triple dots): What is it, How to Use
A roadworks barrier with three warning lamps as the ellipsis placeholder in def later(): ...

Python Ellipsis (triple dots): What is it, How to Use

By Erik van Baaren · Published January 19, 2021 · Updated November 10, 2026

Chances are, you never ran into the Python ellipsis, consisting of three consecutive dots (…). I did, and I decided to do some research and find out more about this somewhat mysterious language element. Let’s go and explore together!

What is the Python ellipsis?

An ellipsis is built from three consecutive dots, like this: …

It’s a well-known language construct in many western languages. But it’s also part of the Python programming language! Let’s inspect this thing in the REPL:

>>> ...
Ellipsis
>>> # OK, it's an object (like everything in Python)
>>> type(...)
<class 'ellipsis'>
>>> help(...)

Help on ellipsis object:

class ellipsis(object)
 |  The type of the Ellipsis singleton.
 |
 |  Methods defined here:
 |
 |  __reduce__(self, /)
 |      Helper for pickle.
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |
 |  __new__(*args, **kwargs)
 |      Create and return a new object.  See help(type) for accurate signature.
Code language: Python (python)

There is exactly one instance of the class ellipsis, called Ellipsis, and ... is just another way to write it: ... is Ellipsis gives True. If you ever need the type itself, for example in a type hint, it’s available as types.EllipsisType. That’s all not very helpful, so let’s see what the official documentation has to say about this mysterious thing. Turns out there’s not much there, either:

‘Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.’

Looks like this ain’t gonna be a walk in the park. We’ll need to do more digging! After some searching, I found out the following uses for the Ellipsis object.

Where do we use the Python ellipsis?

Python ellipsis as a placeholder

You can use it as a placeholder, e.g. when you intend to fill in a Python function later on, but still want to have a valid syntax:

def todo():
    ...Code language: Python (python)

Many people use pass in such cases, but this looks nicer (personal taste, of course), and there are no real downsides I can think of.

The ellipsis in type hints and stub files

These days, the place where you’re most likely to see the ellipsis is in type hints. It has a special meaning in a few spots:

  • tuple[int, ...] means a tuple of any length that contains only integers. Without the ellipsis, tuple[int] would mean a tuple with exactly one integer.
  • Callable[..., str] means a function that takes any arguments and returns a string.
  • In a Protocol class, or any method you only declare without implementing, people write ... as the body.

Here’s what that looks like in code:

from collections.abc import Callable
from typing import Protocol


def average(numbers: tuple[int, ...]) -> float:
    return sum(numbers) / len(numbers)


def call_twice(func: Callable[..., str]) -> None:
    print(func())
    print(func())


class Greeter(Protocol):
    def greet(self, name: str) -> str: ...Code language: Python (python)

You’ll also find the ellipsis all over stub files. These are files with a .pyi extension that only contain type information for a module, for example for a library written in C. Every function body and default value in a stub is replaced by ...:

def average(numbers: tuple[int, ...]) -> float: ...
def connect(host: str, port: int = ...) -> None: ...Code language: Python (python)

Type checkers and editors read these files to give you code completion and warnings. The typing module documentation has all the details.

The ellipsis in NumPy slice notation

Another well-known application of the ellipsis is in the NumPy library. With NumPy, you can slice multiple dimensions at once by using commas. To demonstrate, first create a simple three-dimensional matrix:

>>> x = np.array([   [ [1],[2],[3] ], [ [4],[5],[6] ]   ])Code language: Python (python)

Now these two operations are equivalent:

>>> x[:,:]
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])

>>> x[...]
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])Code language: Python (python)

To get all the data elements at index 1 of the first dimension (the second element, since we count from 0):

>>> x[1, ...]
array([[4],
       [5],
       [6]])Code language: Python (python)

The ellipsis stands for “all remaining dimensions”, so it also works at the front. x[..., 0] takes index 0 of the last dimension:

>>> x[..., 0]
array([[1, 2, 3],
       [4, 5, 6]])Code language: Python (python)

You can find a more thorough explanation on this blog and the NumPy docs.

End of queue marker

Some use the ellipsis to mark the end of a queue. It makes sense:

  • You don’t need to create a custom object
  • It’s not something that you usually encounter in queues, so it’s unique enough to be an end-of-queue marker

Circular references

When creating circular references, Python shows an ellipsis in the REPL:

>>> a = [0, 1]
>>> a[0] = a
>>> a
[[...], 1]Code language: Python (python)

This doesn’t mean Python replaces the reference with an ellipsis, it just shows one instead of crashing in an infinite loop and/or filling up your screen. You can test this yourself. You can keep asking for nested objects, and it will still result in the original a:

>>> a = [0, 1]
>>> a[0] = a
>>> a[0][0][0][0][0][0][0][0][0][0]
[[...], 1]Code language: Python (python)

Erik van Baaren

Erik is the owner of Python Land and the author of many of the articles and tutorials on this website. He's been working as a professional software developer for 25 years, and he holds a Master of Science degree in computer science. His favorite language of choice: Python! Writing good articles takes time and effort. Did you like this tutorial? You can buy him a coffee to show your appreciation.

More about Erik

Try this yourself, right now

Practice conditions in the browser

The same topic as an interactive lesson: short explanation, then code you run and change in your browser, with instant feedback.

Open the interactive lesson

Free to start. Certificates and AI help with Guided.

Monty, your Python learning guide, smiling and waving

1 thought on “Python Ellipsis (triple dots): What is it, How to Use”

  1. 6d6066bc33cebf03fe71a1d30867b777
    September 21, 2022 at 8:21 pm

    I like … as a replacement for pass because you can put a breakpoint on … but not on pass because pass doesn’t generate any bytecode. It also looks nicer and conveys the thought “to be continued…”

    Log in to Reply

Leave a Comment Cancel reply

You must be logged in to post a comment.

Subscribe to my newsletter for Python news, tips, and tricks!

Footer subscribe

  • Home
  • Python Courses
  • Privacy Policy
  • About Us
  • Contact us
©2026 Python Land - All rights reserved
Python Land is not affiliated with Python.org or the Python Software Foundation
  • Free Tutorial
    • Install Python
      • Online Python Interpreter
      • How To Open Python on Windows, Mac, Linux
    • Introduction to Python
      • The Python REPL
      • Python Variable
      • Python String
      • Python Print function
      • Python Booleans
      • For-loop and While-loop
      • Python Functions
      • Your First Python Program
      • Python Comments
    • Creating Python Programs
      • The Best Python IDE
      • Installing VSCode
      • VSCode Python Extensions
      • VSCode GUI Tour
      • Python in VSCode: Running and Debugging
    • Classes and Objects in Python
      • Python Constructor
      • Python Inheritance
    • Structure Your Project
      • Python Modules And Importing
      • Python Packages
    • Python Data Types
      • Python Integer
      • Python Float
      • Python Tuple
      • Python List
      • Python Set
      • Python Dictionary
    • Language Deep Dives
      • Python Try Except (Exceptions)
      • Python Functions: Advanced Concepts
      • List Comprehension
      • Python Iterator
      • Python Range
      • Python Docstrings
      • Python pass (Do Nothing)
    • Interaction with the OS
      • Python Read And Write File
      • Python Subprocess: Run External Commands
    • Venvs / Package Management
      • Working With Python’s venv
      • Pip install: the Python package manager
      • Python Poetry: Package and venv Management Made Easy
      • Python Pipenv: Another Package Manager
      • Pipx: Safely Install Packages Globally
    • Python Concurrency
      • The Python GIL (Global Interpreter Lock)
      • Setting the Baseline
      • Python Threading
      • Python Multiprocessing
    • Data Processing with Python
      • Working With JSON
        • JMESPath Python: JSON Query Language
      • Python YAML: How to Load, Read, and Write YAML
      • Python CSV: Read And Write CSV Files
    • Migrating From Python 2 to 3
      • Check Python Version On The Command-Line
      • How to Migrate To Python 3
      • Python 3 Advantages
    • Using The Unix Shell
      • Basic Linux Commands
      • Bash Scripts
      • Using the Find Command in Linux
      • Unix Pipes
      • Process and Highlight JSON with jq
      • Using the Bash History
      • Bash Multiprocessing
    • Deployment
      • PyInstaller: Create An Executable From Python Code
      • How To Use Docker To Containerize Your Python Project
      • Automatically Build and Deploy Your Python Application with CI/CD
      • Guerrilla Scale Your Web Application
    • Data Science
      • Jupyter Notebook
      • NumPy: Getting Started Tutorial
    • Python Learning Resources
  • Python Courses
  • Blog
  • Login / Register