3 Uses of the Ellipsis in Python

The cutest syntax sugar in Python

Yang Zhou
TechToFreedom

--

Python has a special built-in singleton object called “Ellipsis”. If we input three dots or the word “Ellipsis” in a Python interactive shell, the results are as following:

>>> ...
Ellipsis
>>> Ellipsis
Ellipsis

This simple object seems inconspicuous, but if we use it properly, it can make our lives easier.

This article will introduce the common three scenarios where the ellipsis can be used. After reading, you’ll like this cute singleton object of Python. 😃

1. An Ellipsis Is a Placeholder for Unwritten Code

When designing a new module, we usually define some functions or classes but won’t implement them immediately. Because we only want to determine what we need to write in future and don’t care too much about the implementation details at this early stage. In this scenario, the ellipsis is our best friend:

def write_an_article():
...


class Article:
...

As shown above, we can just use an ellipsis as a placeholder for a function or a class.

Generally speaking, it’s a good programming practice that we design the needed things at first and implement them later. Because this way can help…

--

--