Sitemap
CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Common Use Cases of Ellipsis (…) in Python

Learn to use ellipsis in different scenarios in your Python code

2 min readNov 13, 2024

--

Press enter or click to view image in full size
Image by geralt on Pixabay

The Ellipsis in Python is a built-in object represented by three consecutive dots (…). It’s known as the Ellipsis object and can serve several purposes in Python code. In this post, we will introduce different scenarios where Ellipsis (…) is commonly used.

Placeholder for code

Firstly, the ellipsis literal … can be used as a placeholder to indicate that some code is intentionally left empty and will be implemented in the future.

def new_func():
"""This is a new func and will be defined later."""
...

This is similar to using pass in a class or function body but is often preferred for indicating incomplete sections.

Indicate variable-length tuples in type hints

Ellipsis can also be used to denote a tuple of arbitrary length where each element is of the same type.

--

--

Lynn G. Kwong
Lynn G. Kwong

Written by Lynn G. Kwong

I’m a Software Developer (https://lynn-kwong.medium.com/) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers